| 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" |
| 11 #include "net/base/cache_type.h" |
| 11 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 12 #include "net/base/load_flags.h" | 13 #include "net/base/load_flags.h" |
| 13 #include "net/base/load_log_unittest.h" | 14 #include "net/base/load_log_unittest.h" |
| 14 #include "net/base/ssl_cert_request_info.h" | 15 #include "net/base/ssl_cert_request_info.h" |
| 15 #include "net/disk_cache/disk_cache.h" | 16 #include "net/disk_cache/disk_cache.h" |
| 16 #include "net/http/http_byte_range.h" | 17 #include "net/http/http_byte_range.h" |
| 17 #include "net/http/http_request_info.h" | 18 #include "net/http/http_request_info.h" |
| 18 #include "net/http/http_response_headers.h" | 19 #include "net/http/http_response_headers.h" |
| 19 #include "net/http/http_response_info.h" | 20 #include "net/http/http_response_info.h" |
| 20 #include "net/http/http_transaction.h" | 21 #include "net/http/http_transaction.h" |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 explicit MockHttpCache(disk_cache::Backend* disk_cache) | 452 explicit MockHttpCache(disk_cache::Backend* disk_cache) |
| 452 : http_cache_(new MockNetworkLayer(), disk_cache) { | 453 : http_cache_(new MockNetworkLayer(), disk_cache) { |
| 453 } | 454 } |
| 454 | 455 |
| 455 net::HttpCache* http_cache() { return &http_cache_; } | 456 net::HttpCache* http_cache() { return &http_cache_; } |
| 456 | 457 |
| 457 MockNetworkLayer* network_layer() { | 458 MockNetworkLayer* network_layer() { |
| 458 return static_cast<MockNetworkLayer*>(http_cache_.network_layer()); | 459 return static_cast<MockNetworkLayer*>(http_cache_.network_layer()); |
| 459 } | 460 } |
| 460 MockDiskCache* disk_cache() { | 461 MockDiskCache* disk_cache() { |
| 461 return static_cast<MockDiskCache*>(http_cache_.disk_cache()); | 462 return static_cast<MockDiskCache*>(http_cache_.GetBackend()); |
| 462 } | 463 } |
| 463 | 464 |
| 464 private: | 465 private: |
| 465 net::HttpCache http_cache_; | 466 net::HttpCache http_cache_; |
| 466 }; | 467 }; |
| 467 | 468 |
| 468 | 469 |
| 469 //----------------------------------------------------------------------------- | 470 //----------------------------------------------------------------------------- |
| 470 // helpers | 471 // helpers |
| 471 | 472 |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 | 762 |
| 762 TEST(HttpCache, CreateThenDestroy) { | 763 TEST(HttpCache, CreateThenDestroy) { |
| 763 MockHttpCache cache; | 764 MockHttpCache cache; |
| 764 | 765 |
| 765 scoped_ptr<net::HttpTransaction> trans; | 766 scoped_ptr<net::HttpTransaction> trans; |
| 766 int rv = cache.http_cache()->CreateTransaction(&trans); | 767 int rv = cache.http_cache()->CreateTransaction(&trans); |
| 767 EXPECT_EQ(net::OK, rv); | 768 EXPECT_EQ(net::OK, rv); |
| 768 ASSERT_TRUE(trans.get()); | 769 ASSERT_TRUE(trans.get()); |
| 769 } | 770 } |
| 770 | 771 |
| 772 TEST(HttpCache, GetBackend) { |
| 773 // This will initialize a cache object with NULL backend. |
| 774 MockHttpCache cache(NULL); |
| 775 |
| 776 // This will lazily initialize the backend. |
| 777 cache.http_cache()->set_type(net::MEMORY_CACHE); |
| 778 EXPECT_TRUE(cache.http_cache()->GetBackend()); |
| 779 } |
| 780 |
| 771 TEST(HttpCache, SimpleGET) { | 781 TEST(HttpCache, SimpleGET) { |
| 772 MockHttpCache cache; | 782 MockHttpCache cache; |
| 773 | 783 |
| 774 // write to the cache | 784 // write to the cache |
| 775 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 785 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| 776 | 786 |
| 777 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 787 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 778 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 788 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 779 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 789 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 780 } | 790 } |
| (...skipping 2710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3491 std::string headers; | 3501 std::string headers; |
| 3492 response.headers->GetNormalizedHeaders(&headers); | 3502 response.headers->GetNormalizedHeaders(&headers); |
| 3493 | 3503 |
| 3494 EXPECT_EQ("HTTP/1.1 200 OK\n" | 3504 EXPECT_EQ("HTTP/1.1 200 OK\n" |
| 3495 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 3505 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
| 3496 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 3506 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
| 3497 headers); | 3507 headers); |
| 3498 | 3508 |
| 3499 RemoveMockTransaction(&mock_network_response); | 3509 RemoveMockTransaction(&mock_network_response); |
| 3500 } | 3510 } |
| OLD | NEW |