Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: net/http/http_cache_unittest.cc

Issue 6488010: Propagate the remote socket address to URLRequest and to ViewHostMsg_FrameNavigate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use HostPortPair everywhere Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "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/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"
22 #include "net/http/http_response_headers.h" 23 #include "net/http/http_response_headers.h"
23 #include "net/http/http_response_info.h" 24 #include "net/http/http_response_info.h"
(...skipping 3947 matching lines...) Expand 10 before | Expand all | Expand 10 after
3971 EXPECT_TRUE(truncated); 3972 EXPECT_TRUE(truncated);
3972 3973
3973 // And now test the opposite case. 3974 // And now test the opposite case.
3974 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); 3975 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false));
3975 truncated = true; 3976 truncated = true;
3976 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); 3977 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated));
3977 EXPECT_FALSE(truncated); 3978 EXPECT_FALSE(truncated);
3978 entry->Close(); 3979 entry->Close();
3979 } 3980 }
3980 3981
3982 // Tests basic pickling/unpickling of HttpResponseInfo.
3983 TEST(HttpCache, PersistHttpResponseInfo) {
3984 // Set some fields (add more if needed.)
3985 net::HttpResponseInfo response1;
3986 response1.was_cached = false;
3987 response1.socket_address = net::HostPortPair("1.2.3.4", 80);
3988 response1.headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK");
3989
3990 // Pickle.
3991 Pickle pickle;
3992 response1.Persist(&pickle, false, false);
3993
3994 // Unpickle.
3995 net::HttpResponseInfo response2;
3996 bool response_truncated;
3997 EXPECT_TRUE(response2.InitFromPickle(pickle, &response_truncated));
3998 EXPECT_FALSE(response_truncated);
3999
4000 // Verify fields.
4001 EXPECT_TRUE(response2.was_cached); // InitFromPickle sets this flag.
4002 EXPECT_EQ("1.2.3.4", response2.socket_address.host());
4003 EXPECT_EQ(80, response2.socket_address.port());
4004 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine());
4005 }
4006
3981 // Tests that we delete an entry when the request is cancelled before starting 4007 // Tests that we delete an entry when the request is cancelled before starting
3982 // to read from the network. 4008 // to read from the network.
3983 TEST(HttpCache, DoomOnDestruction) { 4009 TEST(HttpCache, DoomOnDestruction) {
3984 MockHttpCache cache; 4010 MockHttpCache cache;
3985 4011
3986 MockHttpRequest request(kSimpleGET_Transaction); 4012 MockHttpRequest request(kSimpleGET_Transaction);
3987 4013
3988 Context* c = new Context(); 4014 Context* c = new Context();
3989 int rv = cache.http_cache()->CreateTransaction(&c->trans); 4015 int rv = cache.http_cache()->CreateTransaction(&c->trans);
3990 EXPECT_EQ(net::OK, rv); 4016 EXPECT_EQ(net::OK, rv);
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
4840 // Now return 200 when validating the entry so the metadata will be lost. 4866 // Now return 200 when validating the entry so the metadata will be lost.
4841 MockTransaction trans2(kTypicalGET_Transaction); 4867 MockTransaction trans2(kTypicalGET_Transaction);
4842 trans2.load_flags = net::LOAD_VALIDATE_CACHE; 4868 trans2.load_flags = net::LOAD_VALIDATE_CACHE;
4843 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); 4869 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response);
4844 EXPECT_TRUE(response.metadata.get() == NULL); 4870 EXPECT_TRUE(response.metadata.get() == NULL);
4845 4871
4846 EXPECT_EQ(3, cache.network_layer()->transaction_count()); 4872 EXPECT_EQ(3, cache.network_layer()->transaction_count());
4847 EXPECT_EQ(4, cache.disk_cache()->open_count()); 4873 EXPECT_EQ(4, cache.disk_cache()->open_count());
4848 EXPECT_EQ(1, cache.disk_cache()->create_count()); 4874 EXPECT_EQ(1, cache.disk_cache()->create_count());
4849 } 4875 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698