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

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

Issue 10829069: Http cache: Make sure that issuing a byte range request (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | net/http/partial_data.cc » ('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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 2742 matching lines...) Expand 10 before | Expand all | Expand 10 after
2753 2753
2754 // And the entry should be gone. 2754 // And the entry should be gone.
2755 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); 2755 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK);
2756 EXPECT_EQ(3, cache.network_layer()->transaction_count()); 2756 EXPECT_EQ(3, cache.network_layer()->transaction_count());
2757 EXPECT_EQ(1, cache.disk_cache()->open_count()); 2757 EXPECT_EQ(1, cache.disk_cache()->open_count());
2758 EXPECT_EQ(2, cache.disk_cache()->create_count()); 2758 EXPECT_EQ(2, cache.disk_cache()->create_count());
2759 2759
2760 RemoveMockTransaction(&kRangeGET_TransactionOK); 2760 RemoveMockTransaction(&kRangeGET_TransactionOK);
2761 } 2761 }
2762 2762
2763 // Tests that we cache 301s for range requests.
2764 TEST(HttpCache, RangeGET_301) {
2765 MockHttpCache cache;
2766 ScopedMockTransaction transaction(kRangeGET_TransactionOK);
2767 transaction.status = "HTTP/1.1 301 Moved Permanently";
2768 transaction.response_headers = "Location: http://www.bar.com/\n";
2769 transaction.data = "";
2770 transaction.handler = NULL;
2771 AddMockTransaction(&transaction);
2772
2773 // Write to the cache.
2774 RunTransactionTest(cache.http_cache(), transaction);
2775 EXPECT_EQ(1, cache.network_layer()->transaction_count());
2776 EXPECT_EQ(0, cache.disk_cache()->open_count());
2777 EXPECT_EQ(1, cache.disk_cache()->create_count());
2778
2779 // Read from the cache.
2780 RunTransactionTest(cache.http_cache(), transaction);
2781 EXPECT_EQ(1, cache.network_layer()->transaction_count());
2782 EXPECT_EQ(1, cache.disk_cache()->open_count());
2783 EXPECT_EQ(1, cache.disk_cache()->create_count());
2784
2785 RemoveMockTransaction(&transaction);
2786 }
2787
2763 // Tests that we can cache range requests when the start or end is unknown. 2788 // Tests that we can cache range requests when the start or end is unknown.
2764 // We start with one suffix request, followed by a request from a given point. 2789 // We start with one suffix request, followed by a request from a given point.
2765 TEST(HttpCache, UnknownRangeGET_1) { 2790 TEST(HttpCache, UnknownRangeGET_1) {
2766 MockHttpCache cache; 2791 MockHttpCache cache;
2767 AddMockTransaction(&kRangeGET_TransactionOK); 2792 AddMockTransaction(&kRangeGET_TransactionOK);
2768 std::string headers; 2793 std::string headers;
2769 2794
2770 // Write to the cache (70-79). 2795 // Write to the cache (70-79).
2771 MockTransaction transaction(kRangeGET_TransactionOK); 2796 MockTransaction transaction(kRangeGET_TransactionOK);
2772 transaction.request_headers = "Range: bytes = -10\r\n" EXTRA_HEADER; 2797 transaction.request_headers = "Range: bytes = -10\r\n" EXTRA_HEADER;
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
3132 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 3157 EXPECT_EQ(2, cache.network_layer()->transaction_count());
3133 EXPECT_EQ(1, cache.disk_cache()->open_count()); 3158 EXPECT_EQ(1, cache.disk_cache()->open_count());
3134 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3159 EXPECT_EQ(1, cache.disk_cache()->create_count());
3135 3160
3136 // The last transaction has finished so make sure the entry is deactivated. 3161 // The last transaction has finished so make sure the entry is deactivated.
3137 MessageLoop::current()->RunAllPending(); 3162 MessageLoop::current()->RunAllPending();
3138 3163
3139 // Make a request for an invalid range. 3164 // Make a request for an invalid range.
3140 MockTransaction transaction3(kRangeGET_TransactionOK); 3165 MockTransaction transaction3(kRangeGET_TransactionOK);
3141 transaction3.request_headers = "Range: bytes = 80-90\r\n" EXTRA_HEADER; 3166 transaction3.request_headers = "Range: bytes = 80-90\r\n" EXTRA_HEADER;
3142 transaction3.data = ""; 3167 transaction3.data = transaction.data;
3143 transaction3.load_flags = net::LOAD_PREFERRING_CACHE; 3168 transaction3.load_flags = net::LOAD_PREFERRING_CACHE;
3144 RunTransactionTestWithResponse(cache.http_cache(), transaction3, &headers); 3169 RunTransactionTestWithResponse(cache.http_cache(), transaction3, &headers);
3145 EXPECT_EQ(2, cache.disk_cache()->open_count()); 3170 EXPECT_EQ(2, cache.disk_cache()->open_count());
3146 EXPECT_EQ(0U, headers.find("HTTP/1.1 416 ")); 3171 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 "));
3147 EXPECT_NE(std::string::npos, headers.find("Content-Range: bytes 0-0/80")); 3172 EXPECT_EQ(std::string::npos, headers.find("Content-Range:"));
3148 EXPECT_NE(std::string::npos, headers.find("Content-Length: 0")); 3173 EXPECT_EQ(std::string::npos, headers.find("Content-Length: 80"));
3149 3174
3150 // Make sure the entry is deactivated. 3175 // Make sure the entry is deactivated.
3151 MessageLoop::current()->RunAllPending(); 3176 MessageLoop::current()->RunAllPending();
3152 3177
3153 // Even though the request was invalid, we should have the entry. 3178 // Even though the request was invalid, we should have the entry.
3154 RunTransactionTest(cache.http_cache(), transaction2); 3179 RunTransactionTest(cache.http_cache(), transaction2);
3155 EXPECT_EQ(3, cache.disk_cache()->open_count()); 3180 EXPECT_EQ(3, cache.disk_cache()->open_count());
3156 3181
3157 // Make sure the entry is deactivated. 3182 // Make sure the entry is deactivated.
3158 MessageLoop::current()->RunAllPending(); 3183 MessageLoop::current()->RunAllPending();
3159 3184
3160 // Now we should receive a range from the server and drop the stored entry. 3185 // Now we should receive a range from the server and drop the stored entry.
3161 handler.set_not_modified(false); 3186 handler.set_not_modified(false);
3162 transaction2.request_headers = kRangeGET_TransactionOK.request_headers; 3187 transaction2.request_headers = kRangeGET_TransactionOK.request_headers;
3163 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); 3188 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers);
3164 Verify206Response(headers, 40, 49); 3189 Verify206Response(headers, 40, 49);
3165 EXPECT_EQ(5, cache.network_layer()->transaction_count()); 3190 EXPECT_EQ(4, cache.network_layer()->transaction_count());
3166 EXPECT_EQ(4, cache.disk_cache()->open_count()); 3191 EXPECT_EQ(4, cache.disk_cache()->open_count());
3167 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3192 EXPECT_EQ(1, cache.disk_cache()->create_count());
3168 3193
3169 RunTransactionTest(cache.http_cache(), transaction2); 3194 RunTransactionTest(cache.http_cache(), transaction2);
3170 EXPECT_EQ(2, cache.disk_cache()->create_count()); 3195 EXPECT_EQ(2, cache.disk_cache()->create_count());
3171 3196
3172 RemoveMockTransaction(&kRangeGET_TransactionOK); 3197 RemoveMockTransaction(&kRangeGET_TransactionOK);
3173 } 3198 }
3174 3199
3175 // Tests that we can handle a 200 response when dealing with sparse entries. 3200 // Tests that we can handle a 200 response when dealing with sparse entries.
(...skipping 1766 matching lines...) Expand 10 before | Expand all | Expand 10 after
4942 4967
4943 // Verify that the entry is marked as incomplete. 4968 // Verify that the entry is marked as incomplete.
4944 disk_cache::Entry* entry; 4969 disk_cache::Entry* entry;
4945 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); 4970 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry));
4946 net::HttpResponseInfo response; 4971 net::HttpResponseInfo response;
4947 bool truncated = false; 4972 bool truncated = false;
4948 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); 4973 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated));
4949 EXPECT_TRUE(truncated); 4974 EXPECT_TRUE(truncated);
4950 entry->Close(); 4975 entry->Close();
4951 } 4976 }
OLDNEW
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | net/http/partial_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698