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" |
11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "base/utf_string_conversions.h" |
12 #include "net/base/cache_type.h" | 13 #include "net/base/cache_type.h" |
13 #include "net/base/cert_status_flags.h" | 14 #include "net/base/cert_status_flags.h" |
14 #include "net/base/load_flags.h" | 15 #include "net/base/load_flags.h" |
15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
16 #include "net/base/net_log_unittest.h" | 17 #include "net/base/net_log_unittest.h" |
17 #include "net/base/ssl_cert_request_info.h" | 18 #include "net/base/ssl_cert_request_info.h" |
18 #include "net/disk_cache/disk_cache.h" | 19 #include "net/disk_cache/disk_cache.h" |
19 #include "net/http/http_byte_range.h" | 20 #include "net/http/http_byte_range.h" |
20 #include "net/http/http_request_headers.h" | 21 #include "net/http/http_request_headers.h" |
21 #include "net/http/http_request_info.h" | 22 #include "net/http/http_request_info.h" |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 "GET", | 808 "GET", |
808 base::Time(), | 809 base::Time(), |
809 "", | 810 "", |
810 net::LOAD_VALIDATE_CACHE, | 811 net::LOAD_VALIDATE_CACHE, |
811 "HTTP/1.1 200 OK", | 812 "HTTP/1.1 200 OK", |
812 "Cache-Control: max-age=10000\n", | 813 "Cache-Control: max-age=10000\n", |
813 base::Time(), | 814 base::Time(), |
814 "<html><body>Google Blah Blah</body></html>", | 815 "<html><body>Google Blah Blah</body></html>", |
815 TEST_MODE_SYNC_NET_START, | 816 TEST_MODE_SYNC_NET_START, |
816 &FastTransactionServer::FastNoStoreHandler, | 817 &FastTransactionServer::FastNoStoreHandler, |
817 0 | 818 0, |
| 819 string16() |
818 }; | 820 }; |
819 | 821 |
820 // This class provides a handler for kRangeGET_TransactionOK so that the range | 822 // This class provides a handler for kRangeGET_TransactionOK so that the range |
821 // request can be served on demand. | 823 // request can be served on demand. |
822 class RangeTransactionServer { | 824 class RangeTransactionServer { |
823 public: | 825 public: |
824 RangeTransactionServer() { | 826 RangeTransactionServer() { |
825 not_modified_ = false; | 827 not_modified_ = false; |
826 modified_ = false; | 828 modified_ = false; |
827 bad_200_ = false; | 829 bad_200_ = false; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 net::LOAD_NORMAL, | 944 net::LOAD_NORMAL, |
943 "HTTP/1.1 206 Partial Content", | 945 "HTTP/1.1 206 Partial Content", |
944 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" | 946 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" |
945 "ETag: \"foo\"\n" | 947 "ETag: \"foo\"\n" |
946 "Accept-Ranges: bytes\n" | 948 "Accept-Ranges: bytes\n" |
947 "Content-Length: 10\n", | 949 "Content-Length: 10\n", |
948 base::Time(), | 950 base::Time(), |
949 "rg: 40-49 ", | 951 "rg: 40-49 ", |
950 TEST_MODE_NORMAL, | 952 TEST_MODE_NORMAL, |
951 &RangeTransactionServer::RangeHandler, | 953 &RangeTransactionServer::RangeHandler, |
952 0 | 954 0, |
| 955 string16() |
953 }; | 956 }; |
954 | 957 |
955 // Verifies the response headers (|response|) match a partial content | 958 // Verifies the response headers (|response|) match a partial content |
956 // response for the range starting at |start| and ending at |end|. | 959 // response for the range starting at |start| and ending at |end|. |
957 void Verify206Response(std::string response, int start, int end) { | 960 void Verify206Response(std::string response, int start, int end) { |
958 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), | 961 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), |
959 response.size())); | 962 response.size())); |
960 scoped_refptr<net::HttpResponseHeaders> headers( | 963 scoped_refptr<net::HttpResponseHeaders> headers( |
961 new net::HttpResponseHeaders(raw_headers)); | 964 new net::HttpResponseHeaders(raw_headers)); |
962 | 965 |
(...skipping 3643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4606 int rv = cache.http_cache()->CreateTransaction(&trans); | 4609 int rv = cache.http_cache()->CreateTransaction(&trans); |
4607 EXPECT_EQ(net::OK, rv); | 4610 EXPECT_EQ(net::OK, rv); |
4608 ASSERT_TRUE(trans.get()); | 4611 ASSERT_TRUE(trans.get()); |
4609 | 4612 |
4610 rv = trans->Start(&request, &callback, net::BoundNetLog()); | 4613 rv = trans->Start(&request, &callback, net::BoundNetLog()); |
4611 if (rv == net::ERR_IO_PENDING) | 4614 if (rv == net::ERR_IO_PENDING) |
4612 rv = callback.WaitForResult(); | 4615 rv = callback.WaitForResult(); |
4613 ASSERT_EQ(net::ERR_CACHE_MISS, rv); | 4616 ASSERT_EQ(net::ERR_CACHE_MISS, rv); |
4614 } | 4617 } |
4615 | 4618 |
| 4619 // Ensure we cache the TLS username in SSLInfo. |
| 4620 TEST(HttpCache, CachesTLSUsername) { |
| 4621 MockHttpCache cache; |
| 4622 |
| 4623 MockTransaction transaction = kSimpleGET_Transaction; |
| 4624 transaction.tls_username = ASCIIToUTF16("user"); |
| 4625 ScopedMockTransaction scoped_transaction(transaction); |
| 4626 |
| 4627 // write to the cache |
| 4628 RunTransactionTest(cache.http_cache(), transaction); |
| 4629 |
| 4630 net::HttpResponseInfo response; |
| 4631 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, |
| 4632 &response); |
| 4633 EXPECT_EQ(ASCIIToUTF16("user"), response.ssl_info.tls_username); |
| 4634 } |
| 4635 |
4616 // Ensure that we don't crash by if left-behind transactions. | 4636 // Ensure that we don't crash by if left-behind transactions. |
4617 TEST(HttpCache, OutlivedTransactions) { | 4637 TEST(HttpCache, OutlivedTransactions) { |
4618 MockHttpCache* cache = new MockHttpCache; | 4638 MockHttpCache* cache = new MockHttpCache; |
4619 | 4639 |
4620 scoped_ptr<net::HttpTransaction> trans; | 4640 scoped_ptr<net::HttpTransaction> trans; |
4621 int rv = cache->http_cache()->CreateTransaction(&trans); | 4641 int rv = cache->http_cache()->CreateTransaction(&trans); |
4622 EXPECT_EQ(net::OK, rv); | 4642 EXPECT_EQ(net::OK, rv); |
4623 | 4643 |
4624 delete cache; | 4644 delete cache; |
4625 trans.reset(); | 4645 trans.reset(); |
(...skipping 214 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. | 4860 // Now return 200 when validating the entry so the metadata will be lost. |
4841 MockTransaction trans2(kTypicalGET_Transaction); | 4861 MockTransaction trans2(kTypicalGET_Transaction); |
4842 trans2.load_flags = net::LOAD_VALIDATE_CACHE; | 4862 trans2.load_flags = net::LOAD_VALIDATE_CACHE; |
4843 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); | 4863 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); |
4844 EXPECT_TRUE(response.metadata.get() == NULL); | 4864 EXPECT_TRUE(response.metadata.get() == NULL); |
4845 | 4865 |
4846 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 4866 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
4847 EXPECT_EQ(4, cache.disk_cache()->open_count()); | 4867 EXPECT_EQ(4, cache.disk_cache()->open_count()); |
4848 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4868 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4849 } | 4869 } |
OLD | NEW |