| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 3960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3971 EXPECT_TRUE(truncated); | 3971 EXPECT_TRUE(truncated); |
| 3972 | 3972 |
| 3973 // And now test the opposite case. | 3973 // And now test the opposite case. |
| 3974 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); | 3974 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); |
| 3975 truncated = true; | 3975 truncated = true; |
| 3976 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); | 3976 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); |
| 3977 EXPECT_FALSE(truncated); | 3977 EXPECT_FALSE(truncated); |
| 3978 entry->Close(); | 3978 entry->Close(); |
| 3979 } | 3979 } |
| 3980 | 3980 |
| 3981 // Tests basic pickling/unpickling of HttpResponseInfo. |
| 3982 TEST(HttpCache, PersistHttpResponseInfo) { |
| 3983 // Set some fields (add more if needed.) |
| 3984 net::HttpResponseInfo response1; |
| 3985 response1.was_cached = false; |
| 3986 response1.socket_address = "[::]:80"; |
| 3987 response1.headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK"); |
| 3988 |
| 3989 // Pickle. |
| 3990 Pickle pickle; |
| 3991 response1.Persist(&pickle, false, false); |
| 3992 |
| 3993 // Unpickle. |
| 3994 net::HttpResponseInfo response2; |
| 3995 bool response_truncated; |
| 3996 EXPECT_TRUE(response2.InitFromPickle(pickle, &response_truncated)); |
| 3997 EXPECT_FALSE(response_truncated); |
| 3998 |
| 3999 // Verify fields. |
| 4000 EXPECT_TRUE(response2.was_cached); // InitFromPickle sets this flag. |
| 4001 EXPECT_EQ("[::]:80", response2.socket_address); |
| 4002 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 4003 } |
| 4004 |
| 3981 // Tests that we delete an entry when the request is cancelled before starting | 4005 // Tests that we delete an entry when the request is cancelled before starting |
| 3982 // to read from the network. | 4006 // to read from the network. |
| 3983 TEST(HttpCache, DoomOnDestruction) { | 4007 TEST(HttpCache, DoomOnDestruction) { |
| 3984 MockHttpCache cache; | 4008 MockHttpCache cache; |
| 3985 | 4009 |
| 3986 MockHttpRequest request(kSimpleGET_Transaction); | 4010 MockHttpRequest request(kSimpleGET_Transaction); |
| 3987 | 4011 |
| 3988 Context* c = new Context(); | 4012 Context* c = new Context(); |
| 3989 int rv = cache.http_cache()->CreateTransaction(&c->trans); | 4013 int rv = cache.http_cache()->CreateTransaction(&c->trans); |
| 3990 EXPECT_EQ(net::OK, rv); | 4014 EXPECT_EQ(net::OK, rv); |
| (...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4840 // Now return 200 when validating the entry so the metadata will be lost. | 4864 // Now return 200 when validating the entry so the metadata will be lost. |
| 4841 MockTransaction trans2(kTypicalGET_Transaction); | 4865 MockTransaction trans2(kTypicalGET_Transaction); |
| 4842 trans2.load_flags = net::LOAD_VALIDATE_CACHE; | 4866 trans2.load_flags = net::LOAD_VALIDATE_CACHE; |
| 4843 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); | 4867 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); |
| 4844 EXPECT_TRUE(response.metadata.get() == NULL); | 4868 EXPECT_TRUE(response.metadata.get() == NULL); |
| 4845 | 4869 |
| 4846 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 4870 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 4847 EXPECT_EQ(4, cache.disk_cache()->open_count()); | 4871 EXPECT_EQ(4, cache.disk_cache()->open_count()); |
| 4848 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4872 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4849 } | 4873 } |
| OLD | NEW |