OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/hash_tables.h" | 8 #include "base/hash_tables.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 5205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5216 // Verify that the entry is marked as incomplete. | 5216 // Verify that the entry is marked as incomplete. |
5217 disk_cache::Entry* entry; | 5217 disk_cache::Entry* entry; |
5218 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); | 5218 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); |
5219 net::HttpResponseInfo response; | 5219 net::HttpResponseInfo response; |
5220 bool truncated = false; | 5220 bool truncated = false; |
5221 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); | 5221 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); |
5222 EXPECT_TRUE(truncated); | 5222 EXPECT_TRUE(truncated); |
5223 entry->Close(); | 5223 entry->Close(); |
5224 } | 5224 } |
5225 | 5225 |
| 5226 // Tests that we handle truncated enries when StopCaching is called. |
| 5227 TEST(HttpCache, StopCachingTruncatedEntry) { |
| 5228 MockHttpCache cache; |
| 5229 TestOldCompletionCallback callback; |
| 5230 MockHttpRequest request(kRangeGET_TransactionOK); |
| 5231 request.extra_headers.Clear(); |
| 5232 request.extra_headers.AddHeaderFromString(EXTRA_HEADER); |
| 5233 AddMockTransaction(&kRangeGET_TransactionOK); |
| 5234 |
| 5235 std::string raw_headers("HTTP/1.1 200 OK\n" |
| 5236 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
| 5237 "ETag: \"foo\"\n" |
| 5238 "Accept-Ranges: bytes\n" |
| 5239 "Content-Length: 80\n"); |
| 5240 CreateTruncatedEntry(raw_headers, &cache); |
| 5241 |
| 5242 { |
| 5243 // Now make a regular request. |
| 5244 scoped_ptr<net::HttpTransaction> trans; |
| 5245 int rv = cache.http_cache()->CreateTransaction(&trans); |
| 5246 EXPECT_EQ(net::OK, rv); |
| 5247 |
| 5248 rv = trans->Start(&request, &callback, net::BoundNetLog()); |
| 5249 EXPECT_EQ(net::OK, callback.GetResult(rv)); |
| 5250 |
| 5251 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
| 5252 rv = trans->Read(buf, 10, &callback); |
| 5253 EXPECT_EQ(callback.GetResult(rv), 10); |
| 5254 |
| 5255 // This is actually going to do nothing. |
| 5256 trans->StopCaching(); |
| 5257 |
| 5258 // We should be able to keep reading. |
| 5259 rv = trans->Read(buf, 256, &callback); |
| 5260 EXPECT_GT(callback.GetResult(rv), 0); |
| 5261 rv = trans->Read(buf, 256, &callback); |
| 5262 EXPECT_GT(callback.GetResult(rv), 0); |
| 5263 rv = trans->Read(buf, 256, &callback); |
| 5264 EXPECT_EQ(callback.GetResult(rv), 0); |
| 5265 } |
| 5266 |
| 5267 // Verify that the disk entry was updated. |
| 5268 disk_cache::Entry* entry; |
| 5269 ASSERT_TRUE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry)); |
| 5270 EXPECT_EQ(80, entry->GetDataSize(1)); |
| 5271 bool truncated = true; |
| 5272 net::HttpResponseInfo response; |
| 5273 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); |
| 5274 EXPECT_FALSE(truncated); |
| 5275 entry->Close(); |
| 5276 |
| 5277 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 5278 } |
| 5279 |
5226 // Tests that we detect truncated rersources from the net when there is | 5280 // Tests that we detect truncated rersources from the net when there is |
5227 // a Content-Length header. | 5281 // a Content-Length header. |
5228 TEST(HttpCache, TruncatedByContentLength) { | 5282 TEST(HttpCache, TruncatedByContentLength) { |
5229 MockHttpCache cache; | 5283 MockHttpCache cache; |
5230 TestOldCompletionCallback callback; | 5284 TestOldCompletionCallback callback; |
5231 | 5285 |
5232 MockTransaction transaction(kSimpleGET_Transaction); | 5286 MockTransaction transaction(kSimpleGET_Transaction); |
5233 AddMockTransaction(&transaction); | 5287 AddMockTransaction(&transaction); |
5234 transaction.response_headers = "Cache-Control: max-age=10000\n" | 5288 transaction.response_headers = "Cache-Control: max-age=10000\n" |
5235 "Content-Length: 100\n"; | 5289 "Content-Length: 100\n"; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5298 new net::DiskCacheBasedSSLHostInfo("https://www.verisign.com", ssl_config, | 5352 new net::DiskCacheBasedSSLHostInfo("https://www.verisign.com", ssl_config, |
5299 &cert_verifier, cache.http_cache()); | 5353 &cert_verifier, cache.http_cache()); |
5300 ssl_host_info->Start(); | 5354 ssl_host_info->Start(); |
5301 DeleteSSLHostInfoOldCompletionCallback callback(ssl_host_info); | 5355 DeleteSSLHostInfoOldCompletionCallback callback(ssl_host_info); |
5302 int rv = ssl_host_info->WaitForDataReady(&callback); | 5356 int rv = ssl_host_info->WaitForDataReady(&callback); |
5303 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 5357 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
5304 // Now complete the backend creation and let the callback run. | 5358 // Now complete the backend creation and let the callback run. |
5305 factory->FinishCreation(); | 5359 factory->FinishCreation(); |
5306 EXPECT_EQ(net::OK, callback.GetResult(rv)); | 5360 EXPECT_EQ(net::OK, callback.GetResult(rv)); |
5307 } | 5361 } |
OLD | NEW |