Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 EXPECT_EQ("max-age=3600,stale-while-revalidate=7200,age=228658821", value); | |
|
tyoshino (SeeGerritForStatus)
2014/07/22 06:31:55
could you please write a comment explaining why th
Adam Rice
2014/07/22 07:27:42
I wrote a comment explaining that I don't know why
| |
| 6454 } | |
| 6455 | |
| 6456 // Verify that the Chrome-Freshness header is sent on a revalidation if the | |
| 6457 // stale-while-revalidate directive was on the response. | |
| 6458 TEST(HttpCache, StaleWhileRevalidateHeader) { | |
| 6459 MockHttpCache cache; | |
| 6460 | |
| 6461 const MockTransaction kStaleWhileRevalidateTransaction = { | |
| 6462 "http://www.example.com/stale-while-revalidate", | |
| 6463 "GET", | |
| 6464 base::Time(), | |
| 6465 "", | |
| 6466 net::LOAD_NORMAL, | |
| 6467 "HTTP/1.1 200 OK", | |
| 6468 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | |
| 6469 "Cache-Control: max-age=3600,stale-while-revalidate=7200\n", | |
| 6470 base::Time(), | |
| 6471 "<title>Testing stale-while-revalidate</title>", | |
| 6472 TEST_MODE_SYNC_NET_START, | |
| 6473 NULL, | |
| 6474 0, | |
| 6475 net::OK}; | |
| 6476 | |
| 6477 ScopedMockTransaction stale_while_revalidate_transaction( | |
| 6478 kStaleWhileRevalidateTransaction); | |
| 6479 | |
| 6480 // write to the cache | |
|
tyoshino (SeeGerritForStatus)
2014/07/22 06:29:34
Use a capital letter at the head of a sentence in
Adam Rice
2014/07/22 07:27:42
Done.
| |
| 6481 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); | |
| 6482 | |
| 6483 // send the request again and check that Chrome-Freshness header is added. | |
| 6484 stale_while_revalidate_transaction.handler = CheckChromeFreshnessHeader; | |
| 6485 | |
| 6486 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); | |
| 6487 } | |
| 6488 | |
| 6489 static void CheckChromeFreshnessAbsent(const net::HttpRequestInfo* request, | |
| 6490 std::string* response_status, | |
| 6491 std::string* response_headers, | |
| 6492 std::string* response_data) { | |
| 6493 EXPECT_FALSE(request->extra_headers.HasHeader("Chrome-Freshness")); | |
| 6494 } | |
| 6495 | |
| 6496 // Verify that the Chrome-Freshness header is not sent when cookies are | |
| 6497 // disabled. | |
| 6498 TEST(HttpCache, StaleWhileRevalidateHeaderNotSent) { | |
|
tyoshino (SeeGerritForStatus)
2014/07/22 06:29:34
ChromeFreshnessHeaderNotSent?
Adam Rice
2014/07/22 07:27:42
Done.
| |
| 6499 MockHttpCache cache; | |
| 6500 | |
| 6501 const MockTransaction kStaleWhileRevalidateTransaction = { | |
| 6502 "http://www.example.com/stale-while-revalidate", | |
| 6503 "GET", | |
| 6504 base::Time(), | |
| 6505 "", | |
| 6506 net::LOAD_DO_NOT_SEND_COOKIES, | |
| 6507 "HTTP/1.1 200 OK", | |
| 6508 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | |
| 6509 "Cache-Control: max-age=3600,stale-while-revalidate=7200\n", | |
| 6510 base::Time(), | |
| 6511 "<title>Testing stale-while-revalidate</title>", | |
| 6512 TEST_MODE_SYNC_NET_START, | |
| 6513 NULL, | |
| 6514 0, | |
| 6515 net::OK}; | |
| 6516 | |
| 6517 ScopedMockTransaction stale_while_revalidate_transaction( | |
| 6518 kStaleWhileRevalidateTransaction); | |
| 6519 | |
| 6520 // write to the cache | |
| 6521 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); | |
| 6522 | |
| 6523 // send the request again and check that Chrome-Freshness header is absent. | |
| 6524 stale_while_revalidate_transaction.handler = CheckChromeFreshnessAbsent; | |
| 6525 | |
| 6526 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); | |
| 6527 } | |
| OLD | NEW |