| 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 3634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3645 transaction.status = "HTTP/1.1 416 Requested Range Not Satisfiable"; | 3645 transaction.status = "HTTP/1.1 416 Requested Range Not Satisfiable"; |
| 3646 RunTransactionTest(cache.http_cache(), transaction); | 3646 RunTransactionTest(cache.http_cache(), transaction); |
| 3647 | 3647 |
| 3648 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3648 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 3649 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3649 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 3650 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3650 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 3651 | 3651 |
| 3652 RemoveMockTransaction(&transaction); | 3652 RemoveMockTransaction(&transaction); |
| 3653 } | 3653 } |
| 3654 | 3654 |
| 3655 // Tests that we don't cache partial responses that can't be validated. | 3655 // Tests that we store partial responses that can't be validated, as they can |
| 3656 // be used for requests that don't require revalidation. |
| 3656 TEST(HttpCache, RangeGET_NoStrongValidators) { | 3657 TEST(HttpCache, RangeGET_NoStrongValidators) { |
| 3657 MockHttpCache cache; | 3658 MockHttpCache cache; |
| 3658 std::string headers; | 3659 std::string headers; |
| 3659 | 3660 |
| 3660 // Attempt to write to the cache (40-49). | 3661 // Write to the cache (40-49). |
| 3661 MockTransaction transaction(kRangeGET_TransactionOK); | 3662 MockTransaction transaction(kRangeGET_TransactionOK); |
| 3662 AddMockTransaction(&transaction); | 3663 AddMockTransaction(&transaction); |
| 3663 transaction.response_headers = "Content-Length: 10\n" | 3664 transaction.response_headers = "Content-Length: 10\n" |
| 3665 "Cache-Control: max-age=3600\n" |
| 3664 "ETag: w/\"foo\"\n"; | 3666 "ETag: w/\"foo\"\n"; |
| 3665 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 3667 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 3666 | 3668 |
| 3667 Verify206Response(headers, 40, 49); | 3669 Verify206Response(headers, 40, 49); |
| 3668 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3670 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 3669 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3671 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 3670 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3672 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 3671 | 3673 |
| 3672 // Now verify that there's no cached data. | 3674 // Now verify that there's cached data. |
| 3675 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 3676 &headers); |
| 3677 |
| 3678 Verify206Response(headers, 40, 49); |
| 3679 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 3680 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 3681 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 3682 |
| 3683 RemoveMockTransaction(&transaction); |
| 3684 } |
| 3685 |
| 3686 // Tests failures to validate cache partial responses that lack strong |
| 3687 // validators. |
| 3688 TEST(HttpCache, RangeGET_NoValidation) { |
| 3689 MockHttpCache cache; |
| 3690 std::string headers; |
| 3691 |
| 3692 // Write to the cache (40-49). |
| 3693 MockTransaction transaction(kRangeGET_TransactionOK); |
| 3694 AddMockTransaction(&transaction); |
| 3695 transaction.response_headers = "Content-Length: 10\n" |
| 3696 "ETag: w/\"foo\"\n"; |
| 3697 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 3698 |
| 3699 Verify206Response(headers, 40, 49); |
| 3700 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 3701 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 3702 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 3703 |
| 3704 // Now verify that the cached data is not used. |
| 3673 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 3705 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 3674 &headers); | 3706 &headers); |
| 3675 | 3707 |
| 3676 Verify206Response(headers, 40, 49); | 3708 Verify206Response(headers, 40, 49); |
| 3677 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3709 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 3678 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3710 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 3679 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 3711 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 3680 | 3712 |
| 3681 RemoveMockTransaction(&transaction); | 3713 RemoveMockTransaction(&transaction); |
| 3682 } | 3714 } |
| 3683 | 3715 |
| 3684 // Tests that we cache partial responses that lack content-length. | 3716 // Tests that we cache partial responses that lack content-length. |
| 3685 TEST(HttpCache, RangeGET_NoContentLength) { | 3717 TEST(HttpCache, RangeGET_NoContentLength) { |
| 3686 MockHttpCache cache; | 3718 MockHttpCache cache; |
| 3687 std::string headers; | 3719 std::string headers; |
| 3688 | 3720 |
| (...skipping 3094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6783 | 6815 |
| 6784 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 6816 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 6785 | 6817 |
| 6786 // Send the request again and check that Resource-Freshness header is absent. | 6818 // Send the request again and check that Resource-Freshness header is absent. |
| 6787 stale_while_revalidate_transaction.handler = CheckResourceFreshnessAbsent; | 6819 stale_while_revalidate_transaction.handler = CheckResourceFreshnessAbsent; |
| 6788 | 6820 |
| 6789 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); | 6821 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); |
| 6790 | 6822 |
| 6791 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 6823 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 6792 } | 6824 } |
| OLD | NEW |