OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 #include "net/base/cache_type.h" | 12 #include "net/base/cache_type.h" |
13 #include "net/base/cert_status_flags.h" | 13 #include "net/base/cert_status_flags.h" |
14 #include "net/base/host_port_pair.h" | 14 #include "net/base/host_port_pair.h" |
15 #include "net/base/load_flags.h" | 15 #include "net/base/load_flags.h" |
16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
17 #include "net/base/net_log_unittest.h" | 17 #include "net/base/net_log_unittest.h" |
18 #include "net/base/ssl_cert_request_info.h" | 18 #include "net/base/ssl_cert_request_info.h" |
| 19 #include "net/base/ssl_config_service.h" |
19 #include "net/disk_cache/disk_cache.h" | 20 #include "net/disk_cache/disk_cache.h" |
| 21 #include "net/http/disk_cache_based_ssl_host_info.h" |
20 #include "net/http/http_byte_range.h" | 22 #include "net/http/http_byte_range.h" |
21 #include "net/http/http_request_headers.h" | 23 #include "net/http/http_request_headers.h" |
22 #include "net/http/http_request_info.h" | 24 #include "net/http/http_request_info.h" |
23 #include "net/http/http_response_headers.h" | 25 #include "net/http/http_response_headers.h" |
24 #include "net/http/http_response_info.h" | 26 #include "net/http/http_response_info.h" |
25 #include "net/http/http_transaction.h" | 27 #include "net/http/http_transaction.h" |
26 #include "net/http/http_transaction_unittest.h" | 28 #include "net/http/http_transaction_unittest.h" |
27 #include "net/http/http_util.h" | 29 #include "net/http/http_util.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
29 | 31 |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 | 1033 |
1032 int result; | 1034 int result; |
1033 TestCompletionCallback callback; | 1035 TestCompletionCallback callback; |
1034 scoped_ptr<net::HttpTransaction> trans; | 1036 scoped_ptr<net::HttpTransaction> trans; |
1035 }; | 1037 }; |
1036 | 1038 |
1037 } // namespace | 1039 } // namespace |
1038 | 1040 |
1039 | 1041 |
1040 //----------------------------------------------------------------------------- | 1042 //----------------------------------------------------------------------------- |
1041 // tests | 1043 // HttpCache tests |
1042 | 1044 |
1043 TEST(HttpCache, CreateThenDestroy) { | 1045 TEST(HttpCache, CreateThenDestroy) { |
1044 MockHttpCache cache; | 1046 MockHttpCache cache; |
1045 | 1047 |
1046 scoped_ptr<net::HttpTransaction> trans; | 1048 scoped_ptr<net::HttpTransaction> trans; |
1047 int rv = cache.http_cache()->CreateTransaction(&trans); | 1049 int rv = cache.http_cache()->CreateTransaction(&trans); |
1048 EXPECT_EQ(net::OK, rv); | 1050 EXPECT_EQ(net::OK, rv); |
1049 ASSERT_TRUE(trans.get()); | 1051 ASSERT_TRUE(trans.get()); |
1050 } | 1052 } |
1051 | 1053 |
(...skipping 4121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5173 | 5175 |
5174 // Verify that the entry is marked as incomplete. | 5176 // Verify that the entry is marked as incomplete. |
5175 disk_cache::Entry* entry; | 5177 disk_cache::Entry* entry; |
5176 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); | 5178 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); |
5177 net::HttpResponseInfo response; | 5179 net::HttpResponseInfo response; |
5178 bool truncated = false; | 5180 bool truncated = false; |
5179 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); | 5181 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); |
5180 EXPECT_TRUE(truncated); | 5182 EXPECT_TRUE(truncated); |
5181 entry->Close(); | 5183 entry->Close(); |
5182 } | 5184 } |
| 5185 |
| 5186 //----------------------------------------------------------------------------- |
| 5187 // DiskCacheBasedSSLHostInfo tests |
| 5188 |
| 5189 class DeleteSSLHostInfoCompletionCallback : public TestCompletionCallback { |
| 5190 public: |
| 5191 explicit DeleteSSLHostInfoCompletionCallback(net::SSLHostInfo* ssl_host_info) |
| 5192 : ssl_host_info_(ssl_host_info) {} |
| 5193 |
| 5194 virtual void RunWithParams(const Tuple1<int>& params) { |
| 5195 delete ssl_host_info_; |
| 5196 TestCompletionCallback::RunWithParams(params); |
| 5197 } |
| 5198 |
| 5199 private: |
| 5200 net::SSLHostInfo* ssl_host_info_; |
| 5201 }; |
| 5202 |
| 5203 // Tests that we can delete a DiskCacheBasedSSLHostInfo object in a |
| 5204 // completion callback for DiskCacheBasedSSLHostInfo::WaitForDataReady. |
| 5205 TEST(DiskCacheBasedSSLHostInfo, DeleteInCallback) { |
| 5206 net::CertVerifier cert_verifier; |
| 5207 // Use the blocking mock backend factory to force asynchronous completion |
| 5208 // of ssl_host_info->WaitForDataReady(), so that the callback will run. |
| 5209 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); |
| 5210 MockHttpCache cache(factory); |
| 5211 net::SSLConfig ssl_config; |
| 5212 net::SSLHostInfo* ssl_host_info = |
| 5213 new net::DiskCacheBasedSSLHostInfo("https://www.verisign.com", ssl_config, |
| 5214 &cert_verifier, cache.http_cache()); |
| 5215 ssl_host_info->Start(); |
| 5216 DeleteSSLHostInfoCompletionCallback callback(ssl_host_info); |
| 5217 int rv = ssl_host_info->WaitForDataReady(&callback); |
| 5218 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
| 5219 // Now complete the backend creation and let the callback run. |
| 5220 factory->FinishCreation(); |
| 5221 EXPECT_EQ(net::OK, callback.GetResult(rv)); |
| 5222 } |
OLD | NEW |