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

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

Issue 793823002: Let prefetched resources skip cache revalidation once for a short duration. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments from PS2 Created 6 years 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
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"
13 #include "base/time/default_clock.h"
12 #include "base/time/time.h" 14 #include "base/time/time.h"
13 #include "net/base/load_flags.h" 15 #include "net/base/load_flags.h"
14 #include "net/base/load_timing_info.h" 16 #include "net/base/load_timing_info.h"
15 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
16 #include "net/disk_cache/disk_cache.h" 18 #include "net/disk_cache/disk_cache.h"
17 #include "net/http/http_cache.h" 19 #include "net/http/http_cache.h"
18 #include "net/http/http_request_info.h" 20 #include "net/http/http_request_info.h"
19 #include "net/http/http_response_info.h" 21 #include "net/http/http_response_info.h"
20 #include "net/http/http_transaction.h" 22 #include "net/http/http_transaction.h"
21 #include "testing/gtest/include/gtest/gtest.h" 23 #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; 394 std::string resp_headers = t->response_headers;
393 std::string resp_data = t->data; 395 std::string resp_data = t->data;
394 received_bytes_ = resp_status.size() + resp_headers.size() + resp_data.size(); 396 received_bytes_ = resp_status.size() + resp_headers.size() + resp_data.size();
395 if (t->handler) 397 if (t->handler)
396 (t->handler)(request, &resp_status, &resp_headers, &resp_data); 398 (t->handler)(request, &resp_status, &resp_headers, &resp_data);
397 399
398 std::string header_data = base::StringPrintf( 400 std::string header_data = base::StringPrintf(
399 "%s\n%s\n", resp_status.c_str(), resp_headers.c_str()); 401 "%s\n%s\n", resp_status.c_str(), resp_headers.c_str());
400 std::replace(header_data.begin(), header_data.end(), '\n', '\0'); 402 std::replace(header_data.begin(), header_data.end(), '\n', '\0');
401 403
402 response_.request_time = base::Time::Now(); 404 response_.request_time = transaction_factory_->clock()->Now();
403 if (!t->request_time.is_null()) 405 if (!t->request_time.is_null())
404 response_.request_time = t->request_time; 406 response_.request_time = t->request_time;
405 407
406 response_.was_cached = false; 408 response_.was_cached = false;
407 response_.network_accessed = true; 409 response_.network_accessed = true;
408 410
409 response_.response_time = base::Time::Now(); 411 response_.response_time = transaction_factory_->clock()->Now();
410 if (!t->response_time.is_null()) 412 if (!t->response_time.is_null())
411 response_.response_time = t->response_time; 413 response_.response_time = t->response_time;
412 414
413 response_.headers = new net::HttpResponseHeaders(header_data); 415 response_.headers = new net::HttpResponseHeaders(header_data);
414 response_.vary_data.Init(*request, *response_.headers.get()); 416 response_.vary_data.Init(*request, *response_.headers.get());
415 response_.ssl_info.cert_status = t->cert_status; 417 response_.ssl_info.cert_status = t->cert_status;
416 data_ = resp_data; 418 data_ = resp_data;
417 419
418 if (net_log.net_log()) 420 if (net_log.net_log())
419 socket_log_id_ = net_log.net_log()->NextID(); 421 socket_log_id_ = net_log.net_log()->NextID();
420 422
423 if (request_->load_flags & net::LOAD_PREFETCH)
424 response_.unused_since_prefetch = true;
425
421 if (test_mode_ & TEST_MODE_SYNC_NET_START) 426 if (test_mode_ & TEST_MODE_SYNC_NET_START)
422 return net::OK; 427 return net::OK;
423 428
424 CallbackLater(callback, net::OK); 429 CallbackLater(callback, net::OK);
425 return net::ERR_IO_PENDING; 430 return net::ERR_IO_PENDING;
426 } 431 }
427 432
428 void MockNetworkTransaction::SetBeforeNetworkStartCallback( 433 void MockNetworkTransaction::SetBeforeNetworkStartCallback(
429 const BeforeNetworkStartCallback& callback) { 434 const BeforeNetworkStartCallback& callback) {
430 } 435 }
(...skipping 16 matching lines...) Expand all
447 452
448 void MockNetworkTransaction::RunCallback( 453 void MockNetworkTransaction::RunCallback(
449 const net::CompletionCallback& callback, int result) { 454 const net::CompletionCallback& callback, int result) {
450 callback.Run(result); 455 callback.Run(result);
451 } 456 }
452 457
453 MockNetworkLayer::MockNetworkLayer() 458 MockNetworkLayer::MockNetworkLayer()
454 : transaction_count_(0), 459 : transaction_count_(0),
455 done_reading_called_(false), 460 done_reading_called_(false),
456 stop_caching_called_(false), 461 stop_caching_called_(false),
457 last_create_transaction_priority_(net::DEFAULT_PRIORITY) {} 462 last_create_transaction_priority_(net::DEFAULT_PRIORITY),
463 default_clock_(new base::DefaultClock()),
464 clock_(default_clock_.get()) {
465 }
458 466
459 MockNetworkLayer::~MockNetworkLayer() {} 467 MockNetworkLayer::~MockNetworkLayer() {}
460 468
461 void MockNetworkLayer::TransactionDoneReading() { 469 void MockNetworkLayer::TransactionDoneReading() {
462 done_reading_called_ = true; 470 done_reading_called_ = true;
463 } 471 }
464 472
465 void MockNetworkLayer::TransactionStopCaching() { 473 void MockNetworkLayer::TransactionStopCaching() {
466 stop_caching_called_ = true; 474 stop_caching_called_ = true;
467 } 475 }
(...skipping 11 matching lines...) Expand all
479 } 487 }
480 488
481 net::HttpCache* MockNetworkLayer::GetCache() { 489 net::HttpCache* MockNetworkLayer::GetCache() {
482 return NULL; 490 return NULL;
483 } 491 }
484 492
485 net::HttpNetworkSession* MockNetworkLayer::GetSession() { 493 net::HttpNetworkSession* MockNetworkLayer::GetSession() {
486 return NULL; 494 return NULL;
487 } 495 }
488 496
497 void MockNetworkLayer::SetClock(base::Clock* clock) {
498 DCHECK(default_clock_);
499 clock_ = clock;
500 default_clock_.reset();
rvargas (doing something else) 2014/12/24 02:15:25 sounds like we need only one variable to store the
jkarlin 2015/01/08 16:13:04 Done.
501 }
502
489 //----------------------------------------------------------------------------- 503 //-----------------------------------------------------------------------------
490 // helpers 504 // helpers
491 505
492 int ReadTransaction(net::HttpTransaction* trans, std::string* result) { 506 int ReadTransaction(net::HttpTransaction* trans, std::string* result) {
493 int rv; 507 int rv;
494 508
495 net::TestCompletionCallback callback; 509 net::TestCompletionCallback callback;
496 510
497 std::string content; 511 std::string content;
498 do { 512 do {
499 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); 513 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
500 rv = trans->Read(buf.get(), 256, callback.callback()); 514 rv = trans->Read(buf.get(), 256, callback.callback());
501 if (rv == net::ERR_IO_PENDING) 515 if (rv == net::ERR_IO_PENDING)
502 rv = callback.WaitForResult(); 516 rv = callback.WaitForResult();
503 517
504 if (rv > 0) 518 if (rv > 0)
505 content.append(buf->data(), rv); 519 content.append(buf->data(), rv);
506 else if (rv < 0) 520 else if (rv < 0)
507 return rv; 521 return rv;
508 } while (rv > 0); 522 } while (rv > 0);
509 523
510 result->swap(content); 524 result->swap(content);
511 return net::OK; 525 return net::OK;
512 } 526 }
OLDNEW
« net/http/http_response_info.cc ('K') | « net/http/http_transaction_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698