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

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 PS4 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
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"
rvargas (doing something else) 2015/01/09 02:25:34 This is not needed anymore, right?
jkarlin 2015/01/09 14:03:51 Done.
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_->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_->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 clock_(nullptr) {
464 }
458 465
459 MockNetworkLayer::~MockNetworkLayer() {} 466 MockNetworkLayer::~MockNetworkLayer() {}
460 467
461 void MockNetworkLayer::TransactionDoneReading() { 468 void MockNetworkLayer::TransactionDoneReading() {
462 done_reading_called_ = true; 469 done_reading_called_ = true;
463 } 470 }
464 471
465 void MockNetworkLayer::TransactionStopCaching() { 472 void MockNetworkLayer::TransactionStopCaching() {
466 stop_caching_called_ = true; 473 stop_caching_called_ = true;
467 } 474 }
(...skipping 11 matching lines...) Expand all
479 } 486 }
480 487
481 net::HttpCache* MockNetworkLayer::GetCache() { 488 net::HttpCache* MockNetworkLayer::GetCache() {
482 return NULL; 489 return NULL;
483 } 490 }
484 491
485 net::HttpNetworkSession* MockNetworkLayer::GetSession() { 492 net::HttpNetworkSession* MockNetworkLayer::GetSession() {
486 return NULL; 493 return NULL;
487 } 494 }
488 495
496 base::Time MockNetworkLayer::Now() {
497 if (clock_)
498 return clock_->Now();
499 return base::Time::Now();
500 }
501
489 //----------------------------------------------------------------------------- 502 //-----------------------------------------------------------------------------
490 // helpers 503 // helpers
491 504
492 int ReadTransaction(net::HttpTransaction* trans, std::string* result) { 505 int ReadTransaction(net::HttpTransaction* trans, std::string* result) {
493 int rv; 506 int rv;
494 507
495 net::TestCompletionCallback callback; 508 net::TestCompletionCallback callback;
496 509
497 std::string content; 510 std::string content;
498 do { 511 do {
499 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); 512 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
500 rv = trans->Read(buf.get(), 256, callback.callback()); 513 rv = trans->Read(buf.get(), 256, callback.callback());
501 if (rv == net::ERR_IO_PENDING) 514 if (rv == net::ERR_IO_PENDING)
502 rv = callback.WaitForResult(); 515 rv = callback.WaitForResult();
503 516
504 if (rv > 0) 517 if (rv > 0)
505 content.append(buf->data(), rv); 518 content.append(buf->data(), rv);
506 else if (rv < 0) 519 else if (rv < 0)
507 return rv; 520 return rv;
508 } while (rv > 0); 521 } while (rv > 0);
509 522
510 result->swap(content); 523 result->swap(content);
511 return net::OK; 524 return net::OK;
512 } 525 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698