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

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 14625012: net: Return LoadTiming information in the case of a cache hit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Small fix Created 7 years, 7 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 #endif 10 #endif
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 EXPECT_LE(load_timing_info.request_start, 149 EXPECT_LE(load_timing_info.request_start,
150 load_timing_info.proxy_resolve_start); 150 load_timing_info.proxy_resolve_start);
151 EXPECT_LE(load_timing_info.proxy_resolve_start, 151 EXPECT_LE(load_timing_info.proxy_resolve_start,
152 load_timing_info.proxy_resolve_end); 152 load_timing_info.proxy_resolve_end);
153 EXPECT_LE(load_timing_info.proxy_resolve_end, 153 EXPECT_LE(load_timing_info.proxy_resolve_end,
154 load_timing_info.send_start); 154 load_timing_info.send_start);
155 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); 155 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end);
156 EXPECT_LE(load_timing_info.send_end, load_timing_info.receive_headers_end); 156 EXPECT_LE(load_timing_info.send_end, load_timing_info.receive_headers_end);
157 } 157 }
158 158
159 // Tests load timing in the case that there is no underlying connection. This 159 // Tests load timing information in the case of a cache hit, when no cache
160 // can be used to test in the case of cached responses, errors, or non-HTTP 160 // validation request was sent over the wire.
161 // requests. 161 void TestLoadTimingCacheHitNoNetwork(
162 void TestLoadTimingNoHttpConnection( 162 const net::LoadTimingInfo& load_timing_info) {
163 EXPECT_FALSE(load_timing_info.socket_reused);
164 EXPECT_EQ(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
165
166 EXPECT_FALSE(load_timing_info.request_start_time.is_null());
167 EXPECT_FALSE(load_timing_info.request_start.is_null());
168
169 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing);
170 EXPECT_LE(load_timing_info.request_start, load_timing_info.send_start);
171 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end);
172 EXPECT_LE(load_timing_info.send_end, load_timing_info.receive_headers_end);
173
174 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null());
175 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null());
176 }
177
178 // Tests load timing in the case that there is no HTTP response. This can be
179 // used to test in the case of errors or non-HTTP requests.
180 void TestLoadTimingNoHttpResponse(
163 const net::LoadTimingInfo& load_timing_info) { 181 const net::LoadTimingInfo& load_timing_info) {
164 EXPECT_FALSE(load_timing_info.socket_reused); 182 EXPECT_FALSE(load_timing_info.socket_reused);
165 EXPECT_EQ(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); 183 EXPECT_EQ(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
166 184
167 // Only the request times should be non-null. 185 // Only the request times should be non-null.
168 EXPECT_FALSE(load_timing_info.request_start_time.is_null()); 186 EXPECT_FALSE(load_timing_info.request_start_time.is_null());
169 EXPECT_FALSE(load_timing_info.request_start.is_null()); 187 EXPECT_FALSE(load_timing_info.request_start.is_null());
170 188
171 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); 189 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing);
172 190
(...skipping 3843 matching lines...) Expand 10 before | Expand all | Expand 10 after
4016 EXPECT_EQ(1, d.response_started_count()); 4034 EXPECT_EQ(1, d.response_started_count());
4017 EXPECT_EQ(0, d.bytes_received()); 4035 EXPECT_EQ(0, d.bytes_received());
4018 EXPECT_FALSE(d.received_data_before_response()); 4036 EXPECT_FALSE(d.received_data_before_response());
4019 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 4037 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status());
4020 } 4038 }
4021 } 4039 }
4022 4040
4023 TEST_F(URLRequestTestHTTP, VaryHeader) { 4041 TEST_F(URLRequestTestHTTP, VaryHeader) {
4024 ASSERT_TRUE(test_server_.Start()); 4042 ASSERT_TRUE(test_server_.Start());
4025 4043
4026 // populate the cache 4044 // Populate the cache.
4027 { 4045 {
4028 TestDelegate d; 4046 TestDelegate d;
4029 URLRequest req( 4047 URLRequest req(
4030 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_); 4048 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_);
4031 HttpRequestHeaders headers; 4049 HttpRequestHeaders headers;
4032 headers.SetHeader("foo", "1"); 4050 headers.SetHeader("foo", "1");
4033 req.SetExtraRequestHeaders(headers); 4051 req.SetExtraRequestHeaders(headers);
4034 req.Start(); 4052 req.Start();
4035 MessageLoop::current()->Run(); 4053 MessageLoop::current()->Run();
4054
4055 LoadTimingInfo load_timing_info;
4056 req.GetLoadTimingInfo(&load_timing_info);
4057 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
4036 } 4058 }
4037 4059
4038 // expect a cache hit 4060 // Expect a cache hit.
4039 { 4061 {
4040 TestDelegate d; 4062 TestDelegate d;
4041 URLRequest req( 4063 URLRequest req(
4042 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_); 4064 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_);
4043 HttpRequestHeaders headers; 4065 HttpRequestHeaders headers;
4044 headers.SetHeader("foo", "1"); 4066 headers.SetHeader("foo", "1");
4045 req.SetExtraRequestHeaders(headers); 4067 req.SetExtraRequestHeaders(headers);
4046 req.Start(); 4068 req.Start();
4047 MessageLoop::current()->Run(); 4069 MessageLoop::current()->Run();
4048 4070
4049 EXPECT_TRUE(req.was_cached()); 4071 EXPECT_TRUE(req.was_cached());
4072
4073 LoadTimingInfo load_timing_info;
4074 req.GetLoadTimingInfo(&load_timing_info);
4075 TestLoadTimingCacheHitNoNetwork(load_timing_info);
4050 } 4076 }
4051 4077
4052 // expect a cache miss 4078 // Expect a cache miss.
4053 { 4079 {
4054 TestDelegate d; 4080 TestDelegate d;
4055 URLRequest req( 4081 URLRequest req(
4056 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_); 4082 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_);
4057 HttpRequestHeaders headers; 4083 HttpRequestHeaders headers;
4058 headers.SetHeader("foo", "2"); 4084 headers.SetHeader("foo", "2");
4059 req.SetExtraRequestHeaders(headers); 4085 req.SetExtraRequestHeaders(headers);
4060 req.Start(); 4086 req.Start();
4061 MessageLoop::current()->Run(); 4087 MessageLoop::current()->Run();
4062 4088
4063 EXPECT_FALSE(req.was_cached()); 4089 EXPECT_FALSE(req.was_cached());
4090
4091 LoadTimingInfo load_timing_info;
4092 req.GetLoadTimingInfo(&load_timing_info);
4093 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
4064 } 4094 }
4065 } 4095 }
4066 4096
4067 TEST_F(URLRequestTestHTTP, BasicAuth) { 4097 TEST_F(URLRequestTestHTTP, BasicAuth) {
4068 ASSERT_TRUE(test_server_.Start()); 4098 ASSERT_TRUE(test_server_.Start());
4069 4099
4070 // populate the cache 4100 // populate the cache
4071 { 4101 {
4072 TestDelegate d; 4102 TestDelegate d;
4073 d.set_credentials(AuthCredentials(kUser, kSecret)); 4103 d.set_credentials(AuthCredentials(kUser, kSecret));
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
4187 r.GetLoadTimingInfo(&load_timing_info); 4217 r.GetLoadTimingInfo(&load_timing_info);
4188 // The test server does not support keep alive sockets, so the second 4218 // The test server does not support keep alive sockets, so the second
4189 // request with auth should use a new socket. 4219 // request with auth should use a new socket.
4190 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); 4220 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
4191 EXPECT_NE(load_timing_info_before_auth.socket_log_id, 4221 EXPECT_NE(load_timing_info_before_auth.socket_log_id,
4192 load_timing_info.socket_log_id); 4222 load_timing_info.socket_log_id);
4193 EXPECT_LE(load_timing_info_before_auth.receive_headers_end, 4223 EXPECT_LE(load_timing_info_before_auth.receive_headers_end,
4194 load_timing_info.connect_timing.connect_start); 4224 load_timing_info.connect_timing.connect_start);
4195 } 4225 }
4196 4226
4197 // repeat request with end-to-end validation. since auth-basic results in a 4227 // Repeat request with end-to-end validation. Since auth-basic results in a
4198 // cachable page, we expect this test to result in a 304. in which case, the 4228 // cachable page, we expect this test to result in a 304. In which case, the
4199 // response should be fetched from the cache. 4229 // response should be fetched from the cache.
4200 { 4230 {
4201 TestDelegate d; 4231 TestDelegate d;
4202 d.set_credentials(AuthCredentials(kUser, kSecret)); 4232 d.set_credentials(AuthCredentials(kUser, kSecret));
4203 4233
4204 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); 4234 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_);
4205 r.set_load_flags(LOAD_VALIDATE_CACHE); 4235 r.set_load_flags(LOAD_VALIDATE_CACHE);
4206 r.Start(); 4236 r.Start();
4207 4237
4208 MessageLoop::current()->Run(); 4238 MessageLoop::current()->Run();
4209 4239
4210 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 4240 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
4211 4241
4212 // Should be the same cached document. 4242 // Should be the same cached document.
4213 EXPECT_TRUE(r.was_cached()); 4243 EXPECT_TRUE(r.was_cached());
4214 4244
4245 // Since there was a request that went over the wire, the load timing
4246 // information should include connection times.
4215 LoadTimingInfo load_timing_info; 4247 LoadTimingInfo load_timing_info;
4216 r.GetLoadTimingInfo(&load_timing_info); 4248 r.GetLoadTimingInfo(&load_timing_info);
4217 TestLoadTimingNoHttpConnection(load_timing_info); 4249 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
4218 } 4250 }
4219 } 4251 }
4220 4252
4221 // In this test, we do a POST which the server will 302 redirect. 4253 // In this test, we do a POST which the server will 302 redirect.
4222 // The subsequent transaction should use GET, and should not send the 4254 // The subsequent transaction should use GET, and should not send the
4223 // Content-Type header. 4255 // Content-Type header.
4224 // http://code.google.com/p/chromium/issues/detail?id=843 4256 // http://code.google.com/p/chromium/issues/detail?id=843
4225 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { 4257 TEST_F(URLRequestTestHTTP, Post302RedirectGet) {
4226 ASSERT_TRUE(test_server_.Start()); 4258 ASSERT_TRUE(test_server_.Start());
4227 4259
(...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after
5569 EXPECT_EQ(test_server_.host_port_pair().host(), 5601 EXPECT_EQ(test_server_.host_port_pair().host(),
5570 r.GetSocketAddress().host()); 5602 r.GetSocketAddress().host());
5571 EXPECT_EQ(test_server_.host_port_pair().port(), 5603 EXPECT_EQ(test_server_.host_port_pair().port(),
5572 r.GetSocketAddress().port()); 5604 r.GetSocketAddress().port());
5573 EXPECT_EQ(1, d.response_started_count()); 5605 EXPECT_EQ(1, d.response_started_count());
5574 EXPECT_FALSE(d.received_data_before_response()); 5606 EXPECT_FALSE(d.received_data_before_response());
5575 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 5607 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
5576 5608
5577 LoadTimingInfo load_timing_info; 5609 LoadTimingInfo load_timing_info;
5578 r.GetLoadTimingInfo(&load_timing_info); 5610 r.GetLoadTimingInfo(&load_timing_info);
5579 TestLoadTimingNoHttpConnection(load_timing_info); 5611 TestLoadTimingNoHttpResponse(load_timing_info);
5580 } 5612 }
5581 } 5613 }
5582 5614
5583 // Flaky, see http://crbug.com/25045. 5615 // Flaky, see http://crbug.com/25045.
5584 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPassword) { 5616 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPassword) {
5585 ASSERT_TRUE(test_server_.Start()); 5617 ASSERT_TRUE(test_server_.Start());
5586 5618
5587 base::FilePath app_path; 5619 base::FilePath app_path;
5588 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 5620 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
5589 app_path = app_path.AppendASCII("LICENSE"); 5621 app_path = app_path.AppendASCII("LICENSE");
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
5806 5838
5807 EXPECT_FALSE(r.is_pending()); 5839 EXPECT_FALSE(r.is_pending());
5808 EXPECT_EQ(1, d->response_started_count()); 5840 EXPECT_EQ(1, d->response_started_count());
5809 EXPECT_FALSE(d->received_data_before_response()); 5841 EXPECT_FALSE(d->received_data_before_response());
5810 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 5842 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
5811 } 5843 }
5812 } 5844 }
5813 #endif // !defined(DISABLE_FTP_SUPPORT) 5845 #endif // !defined(DISABLE_FTP_SUPPORT)
5814 5846
5815 } // namespace net 5847 } // namespace net
OLDNEW
« net/http/http_cache_unittest.cc ('K') | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698