| 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/scoped_vector.h" | 9 #include "base/scoped_vector.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 2653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2664 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2664 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 2665 | 2665 |
| 2666 // Verify that we have a cached entry. | 2666 // Verify that we have a cached entry. |
| 2667 disk_cache::Entry* en; | 2667 disk_cache::Entry* en; |
| 2668 ASSERT_TRUE(cache.disk_cache()->OpenEntry(kRangeGET_TransactionOK.url, &en)); | 2668 ASSERT_TRUE(cache.disk_cache()->OpenEntry(kRangeGET_TransactionOK.url, &en)); |
| 2669 en->Close(); | 2669 en->Close(); |
| 2670 | 2670 |
| 2671 RemoveMockTransaction(&kRangeGET_TransactionOK); | 2671 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 2672 } | 2672 } |
| 2673 | 2673 |
| 2674 // Tests that we don't crash with a range request if the disk cache was not |
| 2675 // initialized properly. |
| 2676 TEST(HttpCache, RangeGET_NoDiskCache) { |
| 2677 MockHttpCache cache(NULL); |
| 2678 cache.http_cache()->set_enable_range_support(true); |
| 2679 AddMockTransaction(&kRangeGET_TransactionOK); |
| 2680 |
| 2681 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
| 2682 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 2683 |
| 2684 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 2685 } |
| 2686 |
| 2674 #ifdef NDEBUG | 2687 #ifdef NDEBUG |
| 2675 // This test hits a NOTREACHED so it is a release mode only test. | 2688 // This test hits a NOTREACHED so it is a release mode only test. |
| 2676 TEST(HttpCache, RangeGET_OK_LoadOnlyFromCache) { | 2689 TEST(HttpCache, RangeGET_OK_LoadOnlyFromCache) { |
| 2677 MockHttpCache cache; | 2690 MockHttpCache cache; |
| 2678 cache.http_cache()->set_enable_range_support(true); | 2691 cache.http_cache()->set_enable_range_support(true); |
| 2679 AddMockTransaction(&kRangeGET_TransactionOK); | 2692 AddMockTransaction(&kRangeGET_TransactionOK); |
| 2680 | 2693 |
| 2681 // Write to the cache (40-49). | 2694 // Write to the cache (40-49). |
| 2682 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); | 2695 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
| 2683 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2696 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3245 std::string headers; | 3258 std::string headers; |
| 3246 response.headers->GetNormalizedHeaders(&headers); | 3259 response.headers->GetNormalizedHeaders(&headers); |
| 3247 | 3260 |
| 3248 EXPECT_EQ("HTTP/1.1 200 OK\n" | 3261 EXPECT_EQ("HTTP/1.1 200 OK\n" |
| 3249 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 3262 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
| 3250 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 3263 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
| 3251 headers); | 3264 headers); |
| 3252 | 3265 |
| 3253 RemoveMockTransaction(&mock_network_response); | 3266 RemoveMockTransaction(&mock_network_response); |
| 3254 } | 3267 } |
| OLD | NEW |