OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/hash_tables.h" | 7 #include "base/hash_tables.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 2280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2291 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2291 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
2292 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2292 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2293 | 2293 |
2294 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); | 2294 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
2295 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 2295 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
2296 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2296 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2297 | 2297 |
2298 RemoveMockTransaction(&kRangeGET_TransactionOK); | 2298 RemoveMockTransaction(&kRangeGET_TransactionOK); |
2299 } | 2299 } |
2300 | 2300 |
| 2301 // Tests that we don't delete a sparse entry when we cancel a request. |
| 2302 TEST(HttpCache, RangeGET_Cancel) { |
| 2303 MockHttpCache cache; |
| 2304 cache.http_cache()->set_enable_range_support(true); |
| 2305 AddMockTransaction(&kRangeGET_TransactionOK); |
| 2306 |
| 2307 MockHttpRequest request(kRangeGET_TransactionOK); |
| 2308 |
| 2309 Context* c = new Context(cache.http_cache()->CreateTransaction()); |
| 2310 |
| 2311 int rv = c->trans->Start(&request, &c->callback, NULL); |
| 2312 if (rv == net::ERR_IO_PENDING) |
| 2313 rv = c->callback.WaitForResult(); |
| 2314 |
| 2315 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 2316 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 2317 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2318 |
| 2319 // Make sure that the entry has some data stored. |
| 2320 scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(10); |
| 2321 rv = c->trans->Read(buf, buf->size(), &c->callback); |
| 2322 if (rv == net::ERR_IO_PENDING) |
| 2323 rv = c->callback.WaitForResult(); |
| 2324 EXPECT_EQ(buf->size(), rv); |
| 2325 |
| 2326 // Destroy the transaction. |
| 2327 delete c; |
| 2328 |
| 2329 // Verify that the entry has not been deleted. |
| 2330 disk_cache::Entry* entry; |
| 2331 ASSERT_TRUE(cache.disk_cache()->OpenEntry(kRangeGET_TransactionOK.url, |
| 2332 &entry)); |
| 2333 entry->Close(); |
| 2334 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 2335 } |
| 2336 |
2301 #ifdef NDEBUG | 2337 #ifdef NDEBUG |
2302 // This test hits a NOTREACHED so it is a release mode only test. | 2338 // This test hits a NOTREACHED so it is a release mode only test. |
2303 TEST(HttpCache, RangeGET_OK_LoadOnlyFromCache) { | 2339 TEST(HttpCache, RangeGET_OK_LoadOnlyFromCache) { |
2304 MockHttpCache cache; | 2340 MockHttpCache cache; |
2305 cache.http_cache()->set_enable_range_support(true); | 2341 cache.http_cache()->set_enable_range_support(true); |
2306 AddMockTransaction(&kRangeGET_TransactionOK); | 2342 AddMockTransaction(&kRangeGET_TransactionOK); |
2307 | 2343 |
2308 // Write to the cache (40-49). | 2344 // Write to the cache (40-49). |
2309 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); | 2345 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
2310 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2346 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2816 std::string headers; | 2852 std::string headers; |
2817 response.headers->GetNormalizedHeaders(&headers); | 2853 response.headers->GetNormalizedHeaders(&headers); |
2818 | 2854 |
2819 EXPECT_EQ("HTTP/1.1 200 OK\n" | 2855 EXPECT_EQ("HTTP/1.1 200 OK\n" |
2820 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2856 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2821 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2857 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2822 headers); | 2858 headers); |
2823 | 2859 |
2824 RemoveMockTransaction(&mock_network_response); | 2860 RemoveMockTransaction(&mock_network_response); |
2825 } | 2861 } |
OLD | NEW |