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

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

Issue 391763002: Initial implementation of Chrome-Freshness header. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment and test name fixes. Created 6 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_cache.h" 5 #include "net/http/http_cache.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 6425 matching lines...) Expand 10 before | Expand all | Expand 10 after
6436 base::MessageLoop::current()->RunUntilIdle(); 6436 base::MessageLoop::current()->RunUntilIdle();
6437 6437
6438 // Read bytes 20-29 and 50-59 from the network, bytes 30-49 from the cache. 6438 // Read bytes 20-29 and 50-59 from the network, bytes 30-49 from the cache.
6439 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; 6439 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER;
6440 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; 6440 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 ";
6441 received_bytes = RunTransactionAndGetReceivedBytes(cache, transaction); 6441 received_bytes = RunTransactionAndGetReceivedBytes(cache, transaction);
6442 EXPECT_EQ(range_response_size * 2, received_bytes); 6442 EXPECT_EQ(range_response_size * 2, received_bytes);
6443 6443
6444 RemoveMockTransaction(&kRangeGET_TransactionOK); 6444 RemoveMockTransaction(&kRangeGET_TransactionOK);
6445 } 6445 }
6446
6447 static void CheckChromeFreshnessHeader(const net::HttpRequestInfo* request,
6448 std::string* response_status,
6449 std::string* response_headers,
6450 std::string* response_data) {
6451 std::string value;
6452 EXPECT_TRUE(request->extra_headers.GetHeader("Chrome-Freshness", &value));
6453 // 228658821 seconds is around 7.25 years.
6454 // TODO(ricea): Find out why we get this number, and why it is always the
6455 // same.
tyoshino (SeeGerritForStatus) 2014/07/23 00:08:56 Hmm... FYI, 18 Apr 2007 01:10:43 + 228658821sec =
6456 EXPECT_EQ("max-age=3600,stale-while-revalidate=7200,age=228658821", value);
6457 }
6458
6459 // Verify that the Chrome-Freshness header is sent on a revalidation if the
6460 // stale-while-revalidate directive was on the response.
6461 // TODO(ricea): Rename this test when a final name for the header is decided.
6462 TEST(HttpCache, ChromeFreshnessHeaderSent) {
6463 MockHttpCache cache;
6464
6465 const MockTransaction kStaleWhileRevalidateTransaction = {
6466 "http://www.example.com/stale-while-revalidate",
6467 "GET",
6468 base::Time(),
6469 "",
6470 net::LOAD_NORMAL,
6471 "HTTP/1.1 200 OK",
6472 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
6473 "Cache-Control: max-age=3600,stale-while-revalidate=7200\n",
6474 base::Time(),
6475 "<title>Testing stale-while-revalidate</title>",
6476 TEST_MODE_SYNC_NET_START,
6477 NULL,
6478 0,
6479 net::OK};
6480
6481 ScopedMockTransaction stale_while_revalidate_transaction(
6482 kStaleWhileRevalidateTransaction);
6483
6484 // Write to the cache.
6485 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
6486
6487 // Send the request again and check that Chrome-Freshness header is added.
6488 stale_while_revalidate_transaction.handler = CheckChromeFreshnessHeader;
6489
6490 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
6491 }
6492
6493 static void CheckChromeFreshnessAbsent(const net::HttpRequestInfo* request,
6494 std::string* response_status,
6495 std::string* response_headers,
6496 std::string* response_data) {
6497 EXPECT_FALSE(request->extra_headers.HasHeader("Chrome-Freshness"));
6498 }
6499
6500 // Verify that the Chrome-Freshness header is not sent when cookies are
6501 // disabled.
6502 TEST(HttpCache, ChromeFreshnessHeaderNotSent) {
6503 MockHttpCache cache;
6504
6505 const MockTransaction kStaleWhileRevalidateTransaction = {
6506 "http://www.example.com/stale-while-revalidate",
6507 "GET",
6508 base::Time(),
6509 "",
6510 net::LOAD_DO_NOT_SEND_COOKIES,
6511 "HTTP/1.1 200 OK",
6512 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
6513 "Cache-Control: max-age=3600,stale-while-revalidate=7200\n",
6514 base::Time(),
6515 "<title>Testing stale-while-revalidate</title>",
6516 TEST_MODE_SYNC_NET_START,
6517 NULL,
6518 0,
6519 net::OK};
6520
6521 ScopedMockTransaction stale_while_revalidate_transaction(
6522 kStaleWhileRevalidateTransaction);
6523
6524 // Write to the cache.
6525 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
6526
6527 // Send the request again and check that Chrome-Freshness header is absent.
6528 stale_while_revalidate_transaction.handler = CheckChromeFreshnessAbsent;
6529
6530 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
6531 }
OLDNEW
« net/http/http_cache_transaction.cc ('K') | « net/http/http_cache_transaction.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698