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

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: Remove const from directive_size. Created 6 years, 4 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_cache_transaction.cc ('k') | net/http/http_response_headers.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 (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 CheckResourceFreshnessHeader(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(
6453 request->extra_headers.GetHeader("Chromium-Resource-Freshness", &value));
6454 EXPECT_EQ("max-age=3600,stale-while-revalidate=7200,age=10801", value);
6455 }
6456
6457 // Verify that the Chromium-Resource-Freshness header is sent on a revalidation
6458 // if the stale-while-revalidate directive was on the response.
6459 // TODO(ricea): Rename this test when a final name for the header is decided.
6460 TEST(HttpCache, ResourceFreshnessHeaderSent) {
6461 MockHttpCache cache;
6462
6463 ScopedMockTransaction stale_while_revalidate_transaction(
6464 kSimpleGET_Transaction);
6465 stale_while_revalidate_transaction.response_headers =
6466 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
6467 "Age: 10801\n"
6468 "Cache-Control: max-age=3600,stale-while-revalidate=7200\n";
6469
6470 // Write to the cache.
6471 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
6472
6473 EXPECT_EQ(1, cache.network_layer()->transaction_count());
6474
6475 // Send the request again and check that Chromium-Resource-Freshness header is
6476 // added.
6477 stale_while_revalidate_transaction.handler = CheckResourceFreshnessHeader;
6478
6479 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
6480
6481 EXPECT_EQ(2, cache.network_layer()->transaction_count());
6482 }
6483
6484 static void CheckResourceFreshnessAbsent(const net::HttpRequestInfo* request,
6485 std::string* response_status,
6486 std::string* response_headers,
6487 std::string* response_data) {
6488 EXPECT_FALSE(request->extra_headers.HasHeader("Chromium-Resource-Freshness"));
6489 }
6490
6491 // Verify that the Chromium-Resource-Freshness header is not sent when
6492 // stale-while-revalidate is 0.
6493 TEST(HttpCache, ResourceFreshnessHeaderNotSent) {
6494 MockHttpCache cache;
6495
6496 ScopedMockTransaction stale_while_revalidate_transaction(
6497 kSimpleGET_Transaction);
6498 stale_while_revalidate_transaction.response_headers =
6499 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
6500 "Age: 10801\n"
6501 "Cache-Control: max-age=3600,stale-while-revalidate=0\n";
6502
6503 // Write to the cache.
6504 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
6505
6506 EXPECT_EQ(1, cache.network_layer()->transaction_count());
6507
6508 // Send the request again and check that Chromium-Resource-Freshness header is
6509 // absent.
6510 stale_while_revalidate_transaction.handler = CheckResourceFreshnessAbsent;
6511
6512 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
6513
6514 EXPECT_EQ(2, cache.network_layer()->transaction_count());
6515 }
OLDNEW
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | net/http/http_response_headers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698