| 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 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 777 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 778 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 778 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 779 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 779 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 780 } | 780 } |
| 781 | 781 |
| 782 TEST(HttpCache, SimpleGETNoDiskCache) { | 782 TEST(HttpCache, SimpleGETNoDiskCache) { |
| 783 MockHttpCache cache; | 783 MockHttpCache cache; |
| 784 | 784 |
| 785 cache.disk_cache()->set_fail_requests(); | 785 cache.disk_cache()->set_fail_requests(); |
| 786 | 786 |
| 787 scoped_refptr<net::LoadLog> log(new net::LoadLog); | 787 scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded)); |
| 788 | 788 |
| 789 // Read from the network, and don't use the cache. | 789 // Read from the network, and don't use the cache. |
| 790 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, log); | 790 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, log); |
| 791 | 791 |
| 792 // Check that the LoadLog was filled as expected. | 792 // Check that the LoadLog was filled as expected. |
| 793 // (We attempted to both Open and Create entries, but both failed). | 793 // (We attempted to both Open and Create entries, but both failed). |
| 794 EXPECT_EQ(4u, log->events().size()); | 794 EXPECT_EQ(4u, log->events().size()); |
| 795 net::ExpectLogContains(log, 0, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY, | 795 net::ExpectLogContains(log, 0, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY, |
| 796 net::LoadLog::PHASE_BEGIN); | 796 net::LoadLog::PHASE_BEGIN); |
| 797 net::ExpectLogContains(log, 1, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY, | 797 net::ExpectLogContains(log, 1, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 860 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| 861 | 861 |
| 862 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 862 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 863 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 863 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 864 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 864 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 865 } | 865 } |
| 866 | 866 |
| 867 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) { | 867 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) { |
| 868 MockHttpCache cache; | 868 MockHttpCache cache; |
| 869 | 869 |
| 870 scoped_refptr<net::LoadLog> log(new net::LoadLog); | 870 scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded)); |
| 871 | 871 |
| 872 // write to the cache | 872 // write to the cache |
| 873 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, log); | 873 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, log); |
| 874 | 874 |
| 875 // Check that the LoadLog was filled as expected. | 875 // Check that the LoadLog was filled as expected. |
| 876 EXPECT_EQ(6u, log->events().size()); | 876 EXPECT_EQ(6u, log->events().size()); |
| 877 net::ExpectLogContains(log, 0, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY, | 877 net::ExpectLogContains(log, 0, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY, |
| 878 net::LoadLog::PHASE_BEGIN); | 878 net::LoadLog::PHASE_BEGIN); |
| 879 net::ExpectLogContains(log, 1, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY, | 879 net::ExpectLogContains(log, 1, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY, |
| 880 net::LoadLog::PHASE_END); | 880 net::LoadLog::PHASE_END); |
| 881 net::ExpectLogContains(log, 2, net::LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY, | 881 net::ExpectLogContains(log, 2, net::LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY, |
| 882 net::LoadLog::PHASE_BEGIN); | 882 net::LoadLog::PHASE_BEGIN); |
| 883 net::ExpectLogContains(log, 3, net::LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY, | 883 net::ExpectLogContains(log, 3, net::LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY, |
| 884 net::LoadLog::PHASE_END); | 884 net::LoadLog::PHASE_END); |
| 885 net::ExpectLogContains(log, 4, net::LoadLog::TYPE_HTTP_CACHE_WAITING, | 885 net::ExpectLogContains(log, 4, net::LoadLog::TYPE_HTTP_CACHE_WAITING, |
| 886 net::LoadLog::PHASE_BEGIN); | 886 net::LoadLog::PHASE_BEGIN); |
| 887 net::ExpectLogContains(log, 5, net::LoadLog::TYPE_HTTP_CACHE_WAITING, | 887 net::ExpectLogContains(log, 5, net::LoadLog::TYPE_HTTP_CACHE_WAITING, |
| 888 net::LoadLog::PHASE_END); | 888 net::LoadLog::PHASE_END); |
| 889 | 889 |
| 890 // force this transaction to read from the cache | 890 // force this transaction to read from the cache |
| 891 MockTransaction transaction(kSimpleGET_Transaction); | 891 MockTransaction transaction(kSimpleGET_Transaction); |
| 892 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; | 892 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; |
| 893 | 893 |
| 894 log = new net::LoadLog; | 894 log = new net::LoadLog(net::LoadLog::kUnbounded); |
| 895 | 895 |
| 896 RunTransactionTestWithLog(cache.http_cache(), transaction, log); | 896 RunTransactionTestWithLog(cache.http_cache(), transaction, log); |
| 897 | 897 |
| 898 // Check that the LoadLog was filled as expected. | 898 // Check that the LoadLog was filled as expected. |
| 899 EXPECT_EQ(6u, log->events().size()); | 899 EXPECT_EQ(6u, log->events().size()); |
| 900 net::ExpectLogContains(log, 0, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY, | 900 net::ExpectLogContains(log, 0, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY, |
| 901 net::LoadLog::PHASE_BEGIN); | 901 net::LoadLog::PHASE_BEGIN); |
| 902 net::ExpectLogContains(log, 1, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY, | 902 net::ExpectLogContains(log, 1, net::LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY, |
| 903 net::LoadLog::PHASE_END); | 903 net::LoadLog::PHASE_END); |
| 904 net::ExpectLogContains(log, 2, net::LoadLog::TYPE_HTTP_CACHE_WAITING, | 904 net::ExpectLogContains(log, 2, net::LoadLog::TYPE_HTTP_CACHE_WAITING, |
| (...skipping 2586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3491 std::string headers; | 3491 std::string headers; |
| 3492 response.headers->GetNormalizedHeaders(&headers); | 3492 response.headers->GetNormalizedHeaders(&headers); |
| 3493 | 3493 |
| 3494 EXPECT_EQ("HTTP/1.1 200 OK\n" | 3494 EXPECT_EQ("HTTP/1.1 200 OK\n" |
| 3495 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 3495 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
| 3496 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 3496 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
| 3497 headers); | 3497 headers); |
| 3498 | 3498 |
| 3499 RemoveMockTransaction(&mock_network_response); | 3499 RemoveMockTransaction(&mock_network_response); |
| 3500 } | 3500 } |
| OLD | NEW |