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

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

Issue 509783002: Http cache: Allow caching of byte ranges without strong validators. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 3634 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 cache partial responses that can't be validated.
davidben 2014/08/29 18:03:23 Nit: Does this seem clearer/accurate? // Tests
rvargas (doing something else) 2014/08/29 19:34:27 I used "Tests that we store partial responses that
3656 TEST(HttpCache, RangeGET_NoStrongValidators) { 3656 TEST(HttpCache, RangeGET_NoStrongValidators) {
3657 MockHttpCache cache; 3657 MockHttpCache cache;
3658 std::string headers; 3658 std::string headers;
3659 3659
3660 // Attempt to write to the cache (40-49). 3660 // Write to the cache (40-49).
3661 MockTransaction transaction(kRangeGET_TransactionOK); 3661 MockTransaction transaction(kRangeGET_TransactionOK);
3662 AddMockTransaction(&transaction); 3662 AddMockTransaction(&transaction);
3663 transaction.response_headers = "Content-Length: 10\n" 3663 transaction.response_headers = "Content-Length: 10\n"
3664 "Cache-Control: max-age=3600\n"
3664 "ETag: w/\"foo\"\n"; 3665 "ETag: w/\"foo\"\n";
3665 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); 3666 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
3666 3667
3667 Verify206Response(headers, 40, 49); 3668 Verify206Response(headers, 40, 49);
3668 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 3669 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3669 EXPECT_EQ(0, cache.disk_cache()->open_count()); 3670 EXPECT_EQ(0, cache.disk_cache()->open_count());
3670 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3671 EXPECT_EQ(1, cache.disk_cache()->create_count());
3671 3672
3672 // Now verify that there's no cached data. 3673 // Now verify that there's cached data.
3674 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK,
3675 &headers);
3676
3677 Verify206Response(headers, 40, 49);
3678 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3679 EXPECT_EQ(1, cache.disk_cache()->open_count());
3680 EXPECT_EQ(1, cache.disk_cache()->create_count());
3681
3682 RemoveMockTransaction(&transaction);
3683 }
3684
3685 // Tests failures to validate cache partial responses.
davidben 2014/08/29 18:03:23 Nit: Does this seem clearer/accurate? // Tests
rvargas (doing something else) 2014/08/29 19:34:27 Done.
3686 TEST(HttpCache, RangeGET_NoValidation) {
3687 MockHttpCache cache;
3688 std::string headers;
3689
3690 // Write to the cache (40-49).
3691 MockTransaction transaction(kRangeGET_TransactionOK);
3692 AddMockTransaction(&transaction);
3693 transaction.response_headers = "Content-Length: 10\n"
3694 "ETag: w/\"foo\"\n";
3695 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
3696
3697 Verify206Response(headers, 40, 49);
3698 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3699 EXPECT_EQ(0, cache.disk_cache()->open_count());
3700 EXPECT_EQ(1, cache.disk_cache()->create_count());
3701
3702 // Now verify that the cached data is not used.
3673 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, 3703 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK,
3674 &headers); 3704 &headers);
3675 3705
3676 Verify206Response(headers, 40, 49); 3706 Verify206Response(headers, 40, 49);
3677 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 3707 EXPECT_EQ(2, cache.network_layer()->transaction_count());
3678 EXPECT_EQ(0, cache.disk_cache()->open_count()); 3708 EXPECT_EQ(1, cache.disk_cache()->open_count());
3679 EXPECT_EQ(2, cache.disk_cache()->create_count()); 3709 EXPECT_EQ(2, cache.disk_cache()->create_count());
3680 3710
3681 RemoveMockTransaction(&transaction); 3711 RemoveMockTransaction(&transaction);
3682 } 3712 }
3683 3713
3684 // Tests that we cache partial responses that lack content-length. 3714 // Tests that we cache partial responses that lack content-length.
3685 TEST(HttpCache, RangeGET_NoContentLength) { 3715 TEST(HttpCache, RangeGET_NoContentLength) {
3686 MockHttpCache cache; 3716 MockHttpCache cache;
3687 std::string headers; 3717 std::string headers;
3688 3718
(...skipping 3094 matching lines...) Expand 10 before | Expand all | Expand 10 after
6783 6813
6784 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 6814 EXPECT_EQ(1, cache.network_layer()->transaction_count());
6785 6815
6786 // Send the request again and check that Resource-Freshness header is absent. 6816 // Send the request again and check that Resource-Freshness header is absent.
6787 stale_while_revalidate_transaction.handler = CheckResourceFreshnessAbsent; 6817 stale_while_revalidate_transaction.handler = CheckResourceFreshnessAbsent;
6788 6818
6789 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); 6819 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
6790 6820
6791 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 6821 EXPECT_EQ(2, cache.network_layer()->transaction_count());
6792 } 6822 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698