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

Side by Side Diff: net/http/http_cache_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 "net/http/http_cache.h" 5 #include "net/http/http_cache.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "net/base/cache_type.h" 13 #include "net/base/cache_type.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/load_timing_info.h"
17 #include "net/base/load_timing_info_test_util.h"
16 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
17 #include "net/base/net_log_unittest.h" 19 #include "net/base/net_log_unittest.h"
18 #include "net/base/upload_bytes_element_reader.h" 20 #include "net/base/upload_bytes_element_reader.h"
19 #include "net/base/upload_data_stream.h" 21 #include "net/base/upload_data_stream.h"
20 #include "net/cert/cert_status_flags.h" 22 #include "net/cert/cert_status_flags.h"
21 #include "net/disk_cache/disk_cache.h" 23 #include "net/disk_cache/disk_cache.h"
22 #include "net/http/http_byte_range.h" 24 #include "net/http/http_byte_range.h"
23 #include "net/http/http_request_headers.h" 25 #include "net/http/http_request_headers.h"
24 #include "net/http/http_request_info.h" 26 #include "net/http/http_request_info.h"
25 #include "net/http/http_response_headers.h" 27 #include "net/http/http_response_headers.h"
26 #include "net/http/http_response_info.h" 28 #include "net/http/http_response_info.h"
27 #include "net/http/http_transaction.h" 29 #include "net/http/http_transaction.h"
28 #include "net/http/http_transaction_delegate.h" 30 #include "net/http/http_transaction_delegate.h"
29 #include "net/http/http_transaction_unittest.h" 31 #include "net/http/http_transaction_unittest.h"
30 #include "net/http/http_util.h" 32 #include "net/http/http_util.h"
31 #include "net/http/mock_http_cache.h" 33 #include "net/http/mock_http_cache.h"
32 #include "net/ssl/ssl_cert_request_info.h" 34 #include "net/ssl/ssl_cert_request_info.h"
33 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
34 36
35 using base::Time; 37 using base::Time;
36 38
37 namespace { 39 namespace {
38 40
41 // Tests the load timing values of a request that goes through a
42 // MockNetworkTransaction.
43 void TestLoadTimingNetworkRequest(const net::LoadTimingInfo& load_timing_info) {
44 EXPECT_FALSE(load_timing_info.socket_reused);
45 EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
46
47 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null());
48 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null());
49
50 net::ExpectConnectTimingHasTimes(load_timing_info.connect_timing,
51 net::CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
52 EXPECT_LE(load_timing_info.connect_timing.connect_end,
53 load_timing_info.send_start);
54
55 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end);
56
57 // Set by URLRequest / URLRequestHttpJob, at a higher level.
58 EXPECT_TRUE(load_timing_info.request_start_time.is_null());
59 EXPECT_TRUE(load_timing_info.request_start.is_null());
60 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null());
61 }
62
63 // Tests the load timing values of a request that receives a cached response.
64 void TestLoadTimingCachedResponse(const net::LoadTimingInfo& load_timing_info) {
65 EXPECT_FALSE(load_timing_info.socket_reused);
66 EXPECT_EQ(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
67
68 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null());
69 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null());
70
71 net::ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing);
72
73 // Only the send start / end times should be sent, and they should have the
74 // same value.
75 EXPECT_FALSE(load_timing_info.send_start.is_null());
76 EXPECT_EQ(load_timing_info.send_start, load_timing_info.send_end);
77
78 // Set by URLRequest / URLRequestHttpJob, at a higher level.
79 EXPECT_TRUE(load_timing_info.request_start_time.is_null());
80 EXPECT_TRUE(load_timing_info.request_start.is_null());
81 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null());
82 }
83
39 class DeleteCacheCompletionCallback : public net::TestCompletionCallbackBase { 84 class DeleteCacheCompletionCallback : public net::TestCompletionCallbackBase {
40 public: 85 public:
41 explicit DeleteCacheCompletionCallback(MockHttpCache* cache) 86 explicit DeleteCacheCompletionCallback(MockHttpCache* cache)
42 : cache_(cache), 87 : cache_(cache),
43 callback_(base::Bind(&DeleteCacheCompletionCallback::OnComplete, 88 callback_(base::Bind(&DeleteCacheCompletionCallback::OnComplete,
44 base::Unretained(this))) { 89 base::Unretained(this))) {
45 } 90 }
46 91
47 const net::CompletionCallback& callback() const { return callback_; } 92 const net::CompletionCallback& callback() const { return callback_; }
48 93
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 std::string content; 165 std::string content;
121 int rv = ReadTransaction(trans, &content); 166 int rv = ReadTransaction(trans, &content);
122 167
123 EXPECT_EQ(net::OK, rv); 168 EXPECT_EQ(net::OK, rv);
124 std::string expected(trans_info.data); 169 std::string expected(trans_info.data);
125 EXPECT_EQ(expected, content); 170 EXPECT_EQ(expected, content);
126 } 171 }
127 172
128 const int kNoDelegateTransactionCheck = -1; 173 const int kNoDelegateTransactionCheck = -1;
129 174
130 void RunTransactionTestWithRequestAndLogAndDelegate( 175 void RunTransactionTestWithRequestAndDelegateAndGetTiming(
131 net::HttpCache* cache, 176 net::HttpCache* cache,
132 const MockTransaction& trans_info, 177 const MockTransaction& trans_info,
133 const MockHttpRequest& request, 178 const MockHttpRequest& request,
134 net::HttpResponseInfo* response_info, 179 net::HttpResponseInfo* response_info,
180 int num_cache_delegate_actions,
181 int num_network_delegate_actions,
135 const net::BoundNetLog& net_log, 182 const net::BoundNetLog& net_log,
136 int num_cache_delegate_actions, 183 net::LoadTimingInfo* load_timing_info) {
137 int num_network_delegate_actions) {
138 net::TestCompletionCallback callback; 184 net::TestCompletionCallback callback;
139 185
140 // write to the cache 186 // write to the cache
141 187
142 scoped_ptr<TestHttpTransactionDelegate> delegate; 188 scoped_ptr<TestHttpTransactionDelegate> delegate;
143 if (num_cache_delegate_actions != kNoDelegateTransactionCheck && 189 if (num_cache_delegate_actions != kNoDelegateTransactionCheck &&
144 num_network_delegate_actions != kNoDelegateTransactionCheck) { 190 num_network_delegate_actions != kNoDelegateTransactionCheck) {
145 delegate.reset( 191 delegate.reset(
146 new TestHttpTransactionDelegate(num_cache_delegate_actions, 192 new TestHttpTransactionDelegate(num_cache_delegate_actions,
147 num_network_delegate_actions)); 193 num_network_delegate_actions));
(...skipping 11 matching lines...) Expand all
159 205
160 if (net::OK != rv) 206 if (net::OK != rv)
161 return; 207 return;
162 208
163 const net::HttpResponseInfo* response = trans->GetResponseInfo(); 209 const net::HttpResponseInfo* response = trans->GetResponseInfo();
164 ASSERT_TRUE(response); 210 ASSERT_TRUE(response);
165 211
166 if (response_info) 212 if (response_info)
167 *response_info = *response; 213 *response_info = *response;
168 214
215 if (load_timing_info) {
216 // If a fake network connection is used, need a NetLog to get a fake socket
217 // ID.
218 EXPECT_TRUE(net_log.net_log());
219 *load_timing_info = net::LoadTimingInfo();
220 trans->GetLoadTimingInfo(load_timing_info);
221 }
222
169 ReadAndVerifyTransaction(trans.get(), trans_info); 223 ReadAndVerifyTransaction(trans.get(), trans_info);
170 } 224 }
171 225
226 void RunTransactionTestWithRequestAndDelegate(
227 net::HttpCache* cache,
228 const MockTransaction& trans_info,
229 const MockHttpRequest& request,
230 net::HttpResponseInfo* response_info,
231 int num_cache_delegate_actions,
232 int num_network_delegate_actions) {
233 RunTransactionTestWithRequestAndDelegateAndGetTiming(
234 cache, trans_info, request, response_info, num_cache_delegate_actions,
235 num_network_delegate_actions, net::BoundNetLog(), NULL);
236 }
237
172 void RunTransactionTestWithRequest(net::HttpCache* cache, 238 void RunTransactionTestWithRequest(net::HttpCache* cache,
173 const MockTransaction& trans_info, 239 const MockTransaction& trans_info,
174 const MockHttpRequest& request, 240 const MockHttpRequest& request,
175 net::HttpResponseInfo* response_info) { 241 net::HttpResponseInfo* response_info) {
176 RunTransactionTestWithRequestAndLogAndDelegate( 242 RunTransactionTestWithRequestAndDelegate(
177 cache, trans_info, request, response_info, net::BoundNetLog(), 243 cache, trans_info, request, response_info, kNoDelegateTransactionCheck,
178 kNoDelegateTransactionCheck, kNoDelegateTransactionCheck); 244 kNoDelegateTransactionCheck);
179 } 245 }
180 246
181 void RunTransactionTestWithLog(net::HttpCache* cache, 247 void RunTransactionTestAndGetTiming(
182 const MockTransaction& trans_info, 248 net::HttpCache* cache,
183 const net::BoundNetLog& log) { 249 const MockTransaction& trans_info,
184 RunTransactionTestWithRequestAndLogAndDelegate( 250 const net::BoundNetLog& log,
185 cache, trans_info, MockHttpRequest(trans_info), NULL, log, 251 net::LoadTimingInfo* load_timing_info) {
186 kNoDelegateTransactionCheck, kNoDelegateTransactionCheck); 252 RunTransactionTestWithRequestAndDelegateAndGetTiming(
253 cache, trans_info, MockHttpRequest(trans_info), NULL,
254 kNoDelegateTransactionCheck, kNoDelegateTransactionCheck, log,
255 load_timing_info);
187 } 256 }
188 257
189 void RunTransactionTestWithDelegate(net::HttpCache* cache, 258 void RunTransactionTestWithDelegate(net::HttpCache* cache,
190 const MockTransaction& trans_info, 259 const MockTransaction& trans_info,
191 int num_cache_delegate_actions, 260 int num_cache_delegate_actions,
192 int num_network_delegate_actions) { 261 int num_network_delegate_actions) {
193 RunTransactionTestWithRequestAndLogAndDelegate( 262 RunTransactionTestWithRequestAndDelegate(
194 cache, trans_info, MockHttpRequest(trans_info), NULL, net::BoundNetLog(), 263 cache, trans_info, MockHttpRequest(trans_info), NULL,
195 num_cache_delegate_actions, num_network_delegate_actions); 264 num_cache_delegate_actions, num_network_delegate_actions);
196 } 265 }
197 266
198 void RunTransactionTest(net::HttpCache* cache, 267 void RunTransactionTest(net::HttpCache* cache,
199 const MockTransaction& trans_info) { 268 const MockTransaction& trans_info) {
200 RunTransactionTestWithLog(cache, trans_info, net::BoundNetLog()); 269 RunTransactionTestAndGetTiming(cache, trans_info, net::BoundNetLog(), NULL);
201 } 270 }
202 271
203 void RunTransactionTestWithResponseInfo(net::HttpCache* cache, 272 void RunTransactionTestWithResponseInfo(net::HttpCache* cache,
204 const MockTransaction& trans_info, 273 const MockTransaction& trans_info,
205 net::HttpResponseInfo* response) { 274 net::HttpResponseInfo* response) {
206 RunTransactionTestWithRequest( 275 RunTransactionTestWithRequest(
207 cache, trans_info, MockHttpRequest(trans_info), response); 276 cache, trans_info, MockHttpRequest(trans_info), response);
208 } 277 }
209 278
279 void RunTransactionTestWithResponseInfoAndGetTiming(
280 net::HttpCache* cache,
281 const MockTransaction& trans_info,
282 net::HttpResponseInfo* response,
283 const net::BoundNetLog& log,
284 net::LoadTimingInfo* load_timing_info) {
285 RunTransactionTestWithRequestAndDelegateAndGetTiming(
286 cache, trans_info, MockHttpRequest(trans_info), response,
287 kNoDelegateTransactionCheck, kNoDelegateTransactionCheck, log,
288 load_timing_info);
289 }
290
210 void RunTransactionTestWithResponse(net::HttpCache* cache, 291 void RunTransactionTestWithResponse(net::HttpCache* cache,
211 const MockTransaction& trans_info, 292 const MockTransaction& trans_info,
212 std::string* response_headers) { 293 std::string* response_headers) {
213 net::HttpResponseInfo response; 294 net::HttpResponseInfo response;
214 RunTransactionTestWithResponseInfo(cache, trans_info, &response); 295 RunTransactionTestWithResponseInfo(cache, trans_info, &response);
215 response.headers->GetNormalizedHeaders(response_headers); 296 response.headers->GetNormalizedHeaders(response_headers);
216 } 297 }
217 298
299 void RunTransactionTestWithResponseAndGetTiming(
300 net::HttpCache* cache,
301 const MockTransaction& trans_info,
302 std::string* response_headers,
303 const net::BoundNetLog& log,
304 net::LoadTimingInfo* load_timing_info) {
305 net::HttpResponseInfo response;
306 RunTransactionTestWithRequestAndDelegateAndGetTiming(
307 cache, trans_info, MockHttpRequest(trans_info), &response,
308 kNoDelegateTransactionCheck, kNoDelegateTransactionCheck,
309 log, load_timing_info);
310 response.headers->GetNormalizedHeaders(response_headers);
311 }
312
218 // This class provides a handler for kFastNoStoreGET_Transaction so that the 313 // This class provides a handler for kFastNoStoreGET_Transaction so that the
219 // no-store header can be included on demand. 314 // no-store header can be included on demand.
220 class FastTransactionServer { 315 class FastTransactionServer {
221 public: 316 public:
222 FastTransactionServer() { 317 FastTransactionServer() {
223 no_store = false; 318 no_store = false;
224 } 319 }
225 ~FastTransactionServer() {} 320 ~FastTransactionServer() {}
226 321
227 void set_no_store(bool value) { no_store = value; } 322 void set_no_store(bool value) { no_store = value; }
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 595
501 disk_cache::Backend* backend; 596 disk_cache::Backend* backend;
502 net::TestCompletionCallback cb; 597 net::TestCompletionCallback cb;
503 // This will lazily initialize the backend. 598 // This will lazily initialize the backend.
504 int rv = cache.http_cache()->GetBackend(&backend, cb.callback()); 599 int rv = cache.http_cache()->GetBackend(&backend, cb.callback());
505 EXPECT_EQ(net::OK, cb.GetResult(rv)); 600 EXPECT_EQ(net::OK, cb.GetResult(rv));
506 } 601 }
507 602
508 TEST(HttpCache, SimpleGET) { 603 TEST(HttpCache, SimpleGET) {
509 MockHttpCache cache; 604 MockHttpCache cache;
605 net::CapturingBoundNetLog log;
606 net::LoadTimingInfo load_timing_info;
510 607
511 // write to the cache 608 // Write to the cache.
512 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 609 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction,
610 log.bound(), &load_timing_info);
513 611
514 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 612 EXPECT_EQ(1, cache.network_layer()->transaction_count());
515 EXPECT_EQ(0, cache.disk_cache()->open_count()); 613 EXPECT_EQ(0, cache.disk_cache()->open_count());
516 EXPECT_EQ(1, cache.disk_cache()->create_count()); 614 EXPECT_EQ(1, cache.disk_cache()->create_count());
615 TestLoadTimingNetworkRequest(load_timing_info);
517 } 616 }
518 617
519 TEST(HttpCache, SimpleGETNoDiskCache) { 618 TEST(HttpCache, SimpleGETNoDiskCache) {
520 MockHttpCache cache; 619 MockHttpCache cache;
521 620
522 cache.disk_cache()->set_fail_requests(); 621 cache.disk_cache()->set_fail_requests();
523 622
524 net::CapturingBoundNetLog log; 623 net::CapturingBoundNetLog log;
525 log.SetLogLevel(net::NetLog::LOG_BASIC); 624 log.SetLogLevel(net::NetLog::LOG_BASIC);
625 net::LoadTimingInfo load_timing_info;
526 626
527 // Read from the network, and don't use the cache. 627 // Read from the network, and don't use the cache.
528 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, 628 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction,
529 log.bound()); 629 log.bound(), &load_timing_info);
530 630
531 // Check that the NetLog was filled as expected. 631 // Check that the NetLog was filled as expected.
532 // (We attempted to both Open and Create entries, but both failed). 632 // (We attempted to both Open and Create entries, but both failed).
533 net::CapturingNetLog::CapturedEntryList entries; 633 net::CapturingNetLog::CapturedEntryList entries;
534 log.GetEntries(&entries); 634 log.GetEntries(&entries);
535 635
536 EXPECT_EQ(6u, entries.size()); 636 EXPECT_EQ(6u, entries.size());
537 EXPECT_TRUE(net::LogContainsBeginEvent( 637 EXPECT_TRUE(net::LogContainsBeginEvent(
538 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); 638 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND));
539 EXPECT_TRUE(net::LogContainsEndEvent( 639 EXPECT_TRUE(net::LogContainsEndEvent(
540 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); 640 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND));
541 EXPECT_TRUE(net::LogContainsBeginEvent( 641 EXPECT_TRUE(net::LogContainsBeginEvent(
542 entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); 642 entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
543 EXPECT_TRUE(net::LogContainsEndEvent( 643 EXPECT_TRUE(net::LogContainsEndEvent(
544 entries, 3, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); 644 entries, 3, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
545 EXPECT_TRUE(net::LogContainsBeginEvent( 645 EXPECT_TRUE(net::LogContainsBeginEvent(
546 entries, 4, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); 646 entries, 4, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY));
547 EXPECT_TRUE(net::LogContainsEndEvent( 647 EXPECT_TRUE(net::LogContainsEndEvent(
548 entries, 5, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); 648 entries, 5, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY));
549 649
550 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 650 EXPECT_EQ(1, cache.network_layer()->transaction_count());
551 EXPECT_EQ(0, cache.disk_cache()->open_count()); 651 EXPECT_EQ(0, cache.disk_cache()->open_count());
552 EXPECT_EQ(0, cache.disk_cache()->create_count()); 652 EXPECT_EQ(0, cache.disk_cache()->create_count());
653 TestLoadTimingNetworkRequest(load_timing_info);
553 } 654 }
554 655
555 TEST(HttpCache, SimpleGETNoDiskCache2) { 656 TEST(HttpCache, SimpleGETNoDiskCache2) {
556 // This will initialize a cache object with NULL backend. 657 // This will initialize a cache object with NULL backend.
557 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); 658 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
558 factory->set_fail(true); 659 factory->set_fail(true);
559 factory->FinishCreation(); // We'll complete synchronously. 660 factory->FinishCreation(); // We'll complete synchronously.
560 MockHttpCache cache(factory); 661 MockHttpCache cache(factory);
561 662
562 // Read from the network, and don't use the cache. 663 // Read from the network, and don't use the cache.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 } 788 }
688 789
689 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) { 790 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) {
690 MockHttpCache cache; 791 MockHttpCache cache;
691 792
692 net::CapturingBoundNetLog log; 793 net::CapturingBoundNetLog log;
693 794
694 // This prevents a number of write events from being logged. 795 // This prevents a number of write events from being logged.
695 log.SetLogLevel(net::NetLog::LOG_BASIC); 796 log.SetLogLevel(net::NetLog::LOG_BASIC);
696 797
697 // write to the cache 798 net::LoadTimingInfo load_timing_info;
698 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, 799
699 log.bound()); 800 // Write to the cache.
801 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction,
802 log.bound(), &load_timing_info);
700 803
701 // Check that the NetLog was filled as expected. 804 // Check that the NetLog was filled as expected.
702 net::CapturingNetLog::CapturedEntryList entries; 805 net::CapturingNetLog::CapturedEntryList entries;
703 log.GetEntries(&entries); 806 log.GetEntries(&entries);
704 807
705 EXPECT_EQ(8u, entries.size()); 808 EXPECT_EQ(8u, entries.size());
706 EXPECT_TRUE(net::LogContainsBeginEvent( 809 EXPECT_TRUE(net::LogContainsBeginEvent(
707 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); 810 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND));
708 EXPECT_TRUE(net::LogContainsEndEvent( 811 EXPECT_TRUE(net::LogContainsEndEvent(
709 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); 812 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND));
710 EXPECT_TRUE(net::LogContainsBeginEvent( 813 EXPECT_TRUE(net::LogContainsBeginEvent(
711 entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); 814 entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
712 EXPECT_TRUE(net::LogContainsEndEvent( 815 EXPECT_TRUE(net::LogContainsEndEvent(
713 entries, 3, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); 816 entries, 3, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
714 EXPECT_TRUE(net::LogContainsBeginEvent( 817 EXPECT_TRUE(net::LogContainsBeginEvent(
715 entries, 4, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); 818 entries, 4, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY));
716 EXPECT_TRUE(net::LogContainsEndEvent( 819 EXPECT_TRUE(net::LogContainsEndEvent(
717 entries, 5, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); 820 entries, 5, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY));
718 EXPECT_TRUE(net::LogContainsBeginEvent( 821 EXPECT_TRUE(net::LogContainsBeginEvent(
719 entries, 6, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); 822 entries, 6, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY));
720 EXPECT_TRUE(net::LogContainsEndEvent( 823 EXPECT_TRUE(net::LogContainsEndEvent(
721 entries, 7, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); 824 entries, 7, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY));
722 825
723 // force this transaction to read from the cache 826 TestLoadTimingNetworkRequest(load_timing_info);
827
828 // Force this transaction to read from the cache.
724 MockTransaction transaction(kSimpleGET_Transaction); 829 MockTransaction transaction(kSimpleGET_Transaction);
725 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; 830 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE;
726 831
727 log.Clear(); 832 log.Clear();
728 833
729 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); 834 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(),
835 &load_timing_info);
730 836
731 // Check that the NetLog was filled as expected. 837 // Check that the NetLog was filled as expected.
732 log.GetEntries(&entries); 838 log.GetEntries(&entries);
733 839
734 EXPECT_EQ(8u, entries.size()); 840 EXPECT_EQ(8u, entries.size());
735 EXPECT_TRUE(net::LogContainsBeginEvent( 841 EXPECT_TRUE(net::LogContainsBeginEvent(
736 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); 842 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND));
737 EXPECT_TRUE(net::LogContainsEndEvent( 843 EXPECT_TRUE(net::LogContainsEndEvent(
738 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); 844 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND));
739 EXPECT_TRUE(net::LogContainsBeginEvent( 845 EXPECT_TRUE(net::LogContainsBeginEvent(
740 entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); 846 entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
741 EXPECT_TRUE(net::LogContainsEndEvent( 847 EXPECT_TRUE(net::LogContainsEndEvent(
742 entries, 3, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY)); 848 entries, 3, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
743 EXPECT_TRUE(net::LogContainsBeginEvent( 849 EXPECT_TRUE(net::LogContainsBeginEvent(
744 entries, 4, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); 850 entries, 4, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY));
745 EXPECT_TRUE(net::LogContainsEndEvent( 851 EXPECT_TRUE(net::LogContainsEndEvent(
746 entries, 5, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); 852 entries, 5, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY));
747 EXPECT_TRUE(net::LogContainsBeginEvent( 853 EXPECT_TRUE(net::LogContainsBeginEvent(
748 entries, 6, net::NetLog::TYPE_HTTP_CACHE_READ_INFO)); 854 entries, 6, net::NetLog::TYPE_HTTP_CACHE_READ_INFO));
749 EXPECT_TRUE(net::LogContainsEndEvent( 855 EXPECT_TRUE(net::LogContainsEndEvent(
750 entries, 7, net::NetLog::TYPE_HTTP_CACHE_READ_INFO)); 856 entries, 7, net::NetLog::TYPE_HTTP_CACHE_READ_INFO));
751 857
752 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 858 EXPECT_EQ(1, cache.network_layer()->transaction_count());
753 EXPECT_EQ(1, cache.disk_cache()->open_count()); 859 EXPECT_EQ(1, cache.disk_cache()->open_count());
754 EXPECT_EQ(1, cache.disk_cache()->create_count()); 860 EXPECT_EQ(1, cache.disk_cache()->create_count());
861 TestLoadTimingCachedResponse(load_timing_info);
755 } 862 }
756 863
757 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Miss) { 864 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Miss) {
758 MockHttpCache cache; 865 MockHttpCache cache;
759 866
760 // force this transaction to read from the cache 867 // force this transaction to read from the cache
761 MockTransaction transaction(kSimpleGET_Transaction); 868 MockTransaction transaction(kSimpleGET_Transaction);
762 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; 869 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE;
763 870
764 MockHttpRequest request(transaction); 871 MockHttpRequest request(transaction);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 transaction.request_headers = "Foo: bar\r\n"; 951 transaction.request_headers = "Foo: bar\r\n";
845 transaction.response_headers = "Cache-Control: max-age=10000\n" 952 transaction.response_headers = "Cache-Control: max-age=10000\n"
846 "Vary: Foo\n"; 953 "Vary: Foo\n";
847 AddMockTransaction(&transaction); 954 AddMockTransaction(&transaction);
848 RunTransactionTest(cache.http_cache(), transaction); 955 RunTransactionTest(cache.http_cache(), transaction);
849 956
850 // Attempt to read from the cache... this is a vary mismatch that must reach 957 // Attempt to read from the cache... this is a vary mismatch that must reach
851 // the network again. 958 // the network again.
852 transaction.load_flags |= net::LOAD_PREFERRING_CACHE; 959 transaction.load_flags |= net::LOAD_PREFERRING_CACHE;
853 transaction.request_headers = "Foo: none\r\n"; 960 transaction.request_headers = "Foo: none\r\n";
854 RunTransactionTest(cache.http_cache(), transaction); 961 net::CapturingBoundNetLog log;
962 net::LoadTimingInfo load_timing_info;
963 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(),
964 &load_timing_info);
855 965
856 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 966 EXPECT_EQ(2, cache.network_layer()->transaction_count());
857 EXPECT_EQ(1, cache.disk_cache()->open_count()); 967 EXPECT_EQ(1, cache.disk_cache()->open_count());
858 EXPECT_EQ(1, cache.disk_cache()->create_count()); 968 EXPECT_EQ(1, cache.disk_cache()->create_count());
969 TestLoadTimingNetworkRequest(load_timing_info);
859 RemoveMockTransaction(&transaction); 970 RemoveMockTransaction(&transaction);
860 } 971 }
861 972
862 // Tests that LOAD_FROM_CACHE_IF_OFFLINE returns proper response on 973 // Tests that LOAD_FROM_CACHE_IF_OFFLINE returns proper response on
863 // network success 974 // network success
864 TEST(HttpCache, SimpleGET_CacheOverride_Network) { 975 TEST(HttpCache, SimpleGET_CacheOverride_Network) {
865 MockHttpCache cache; 976 MockHttpCache cache;
866 977
867 // Prime cache. 978 // Prime cache.
868 MockTransaction transaction(kSimpleGET_Transaction); 979 MockTransaction transaction(kSimpleGET_Transaction);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 1117 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
1007 1118
1008 // Force this transaction to write to the cache again. 1119 // Force this transaction to write to the cache again.
1009 MockTransaction transaction(kSimpleGET_Transaction); 1120 MockTransaction transaction(kSimpleGET_Transaction);
1010 transaction.load_flags |= net::LOAD_BYPASS_CACHE; 1121 transaction.load_flags |= net::LOAD_BYPASS_CACHE;
1011 1122
1012 net::CapturingBoundNetLog log; 1123 net::CapturingBoundNetLog log;
1013 1124
1014 // This prevents a number of write events from being logged. 1125 // This prevents a number of write events from being logged.
1015 log.SetLogLevel(net::NetLog::LOG_BASIC); 1126 log.SetLogLevel(net::NetLog::LOG_BASIC);
1127 net::LoadTimingInfo load_timing_info;
1016 1128
1017 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); 1129 // Write to the cache.
1130 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(),
1131 &load_timing_info);
1018 1132
1019 // Check that the NetLog was filled as expected. 1133 // Check that the NetLog was filled as expected.
1020 net::CapturingNetLog::CapturedEntryList entries; 1134 net::CapturingNetLog::CapturedEntryList entries;
1021 log.GetEntries(&entries); 1135 log.GetEntries(&entries);
1022 1136
1023 EXPECT_EQ(8u, entries.size()); 1137 EXPECT_EQ(8u, entries.size());
1024 EXPECT_TRUE(net::LogContainsBeginEvent( 1138 EXPECT_TRUE(net::LogContainsBeginEvent(
1025 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); 1139 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND));
1026 EXPECT_TRUE(net::LogContainsEndEvent( 1140 EXPECT_TRUE(net::LogContainsEndEvent(
1027 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); 1141 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND));
1028 EXPECT_TRUE(net::LogContainsBeginEvent( 1142 EXPECT_TRUE(net::LogContainsBeginEvent(
1029 entries, 2, net::NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY)); 1143 entries, 2, net::NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY));
1030 EXPECT_TRUE(net::LogContainsEndEvent( 1144 EXPECT_TRUE(net::LogContainsEndEvent(
1031 entries, 3, net::NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY)); 1145 entries, 3, net::NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY));
1032 EXPECT_TRUE(net::LogContainsBeginEvent( 1146 EXPECT_TRUE(net::LogContainsBeginEvent(
1033 entries, 4, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); 1147 entries, 4, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY));
1034 EXPECT_TRUE(net::LogContainsEndEvent( 1148 EXPECT_TRUE(net::LogContainsEndEvent(
1035 entries, 5, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY)); 1149 entries, 5, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY));
1036 EXPECT_TRUE(net::LogContainsBeginEvent( 1150 EXPECT_TRUE(net::LogContainsBeginEvent(
1037 entries, 6, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); 1151 entries, 6, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY));
1038 EXPECT_TRUE(net::LogContainsEndEvent( 1152 EXPECT_TRUE(net::LogContainsEndEvent(
1039 entries, 7, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); 1153 entries, 7, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY));
1040 1154
1041 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 1155 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1042 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1156 EXPECT_EQ(0, cache.disk_cache()->open_count());
1043 EXPECT_EQ(2, cache.disk_cache()->create_count()); 1157 EXPECT_EQ(2, cache.disk_cache()->create_count());
1158 TestLoadTimingNetworkRequest(load_timing_info);
1044 } 1159 }
1045 1160
1046 TEST(HttpCache, SimpleGET_LoadBypassCache_Implicit) { 1161 TEST(HttpCache, SimpleGET_LoadBypassCache_Implicit) {
1047 MockHttpCache cache; 1162 MockHttpCache cache;
1048 1163
1049 // write to the cache 1164 // write to the cache
1050 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 1165 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
1051 1166
1052 // force this transaction to write to the cache again 1167 // force this transaction to write to the cache again
1053 MockTransaction transaction(kSimpleGET_Transaction); 1168 MockTransaction transaction(kSimpleGET_Transaction);
(...skipping 19 matching lines...) Expand all
1073 RunTransactionTest(cache.http_cache(), transaction); 1188 RunTransactionTest(cache.http_cache(), transaction);
1074 1189
1075 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 1190 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1076 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1191 EXPECT_EQ(0, cache.disk_cache()->open_count());
1077 EXPECT_EQ(2, cache.disk_cache()->create_count()); 1192 EXPECT_EQ(2, cache.disk_cache()->create_count());
1078 } 1193 }
1079 1194
1080 TEST(HttpCache, SimpleGET_LoadValidateCache) { 1195 TEST(HttpCache, SimpleGET_LoadValidateCache) {
1081 MockHttpCache cache; 1196 MockHttpCache cache;
1082 1197
1083 // write to the cache 1198 // Write to the cache.
1084 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 1199 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
1085 1200
1086 // read from the cache 1201 // Read from the cache.
1087 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 1202 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
1088 1203
1089 // force this transaction to validate the cache 1204 // Force this transaction to validate the cache.
1090 MockTransaction transaction(kSimpleGET_Transaction); 1205 MockTransaction transaction(kSimpleGET_Transaction);
1091 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; 1206 transaction.load_flags |= net::LOAD_VALIDATE_CACHE;
1092 1207
1093 net::HttpResponseInfo response_info; 1208 net::HttpResponseInfo response_info;
1094 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, 1209 net::CapturingBoundNetLog log;
1095 &response_info); 1210 net::LoadTimingInfo load_timing_info;
1211 RunTransactionTestWithResponseInfoAndGetTiming(
1212 cache.http_cache(), transaction, &response_info, log.bound(),
1213 &load_timing_info);
1096 1214
1097 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 1215 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1098 EXPECT_EQ(1, cache.disk_cache()->open_count()); 1216 EXPECT_EQ(1, cache.disk_cache()->open_count());
1099 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1217 EXPECT_EQ(1, cache.disk_cache()->create_count());
1100 EXPECT_TRUE(response_info.network_accessed); 1218 EXPECT_TRUE(response_info.network_accessed);
1219 TestLoadTimingNetworkRequest(load_timing_info);
1101 } 1220 }
1102 1221
1103 TEST(HttpCache, SimpleGET_LoadValidateCache_Implicit) { 1222 TEST(HttpCache, SimpleGET_LoadValidateCache_Implicit) {
1104 MockHttpCache cache; 1223 MockHttpCache cache;
1105 1224
1106 // write to the cache 1225 // write to the cache
1107 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 1226 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
1108 1227
1109 // read from the cache 1228 // read from the cache
1110 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); 1229 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
1859 TEST(HttpCache, TypicalGET_ConditionalRequest) { 1978 TEST(HttpCache, TypicalGET_ConditionalRequest) {
1860 MockHttpCache cache; 1979 MockHttpCache cache;
1861 1980
1862 // write to the cache 1981 // write to the cache
1863 RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction); 1982 RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction);
1864 1983
1865 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1984 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1866 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1985 EXPECT_EQ(0, cache.disk_cache()->open_count());
1867 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1986 EXPECT_EQ(1, cache.disk_cache()->create_count());
1868 1987
1869 // get the same URL again, but this time we expect it to result 1988 // Get the same URL again, but this time we expect it to result
gavinp 2013/05/10 20:23:03 Awesome!
mmenke 2013/05/10 20:44:00 The fact that I capitalized Get, or the sheer numb
1870 // in a conditional request. 1989 // in a conditional request.
1871 RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction); 1990 net::CapturingBoundNetLog log;
1991 net::LoadTimingInfo load_timing_info;
1992 RunTransactionTestAndGetTiming(cache.http_cache(), kTypicalGET_Transaction,
1993 log.bound(), &load_timing_info);
1872 1994
1873 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 1995 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1874 EXPECT_EQ(1, cache.disk_cache()->open_count()); 1996 EXPECT_EQ(1, cache.disk_cache()->open_count());
1875 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1997 EXPECT_EQ(1, cache.disk_cache()->create_count());
1998 TestLoadTimingNetworkRequest(load_timing_info);
1876 } 1999 }
1877 2000
1878 static void ETagGet_ConditionalRequest_Handler( 2001 static void ETagGet_ConditionalRequest_Handler(
1879 const net::HttpRequestInfo* request, 2002 const net::HttpRequestInfo* request,
1880 std::string* response_status, 2003 std::string* response_status,
1881 std::string* response_headers, 2004 std::string* response_headers,
1882 std::string* response_data) { 2005 std::string* response_data) {
1883 EXPECT_TRUE( 2006 EXPECT_TRUE(
1884 request->extra_headers.HasHeader(net::HttpRequestHeaders::kIfNoneMatch)); 2007 request->extra_headers.HasHeader(net::HttpRequestHeaders::kIfNoneMatch));
1885 response_status->assign("HTTP/1.1 304 Not Modified"); 2008 response_status->assign("HTTP/1.1 304 Not Modified");
1886 response_headers->assign(kETagGET_Transaction.response_headers); 2009 response_headers->assign(kETagGET_Transaction.response_headers);
1887 response_data->clear(); 2010 response_data->clear();
1888 } 2011 }
1889 2012
1890 TEST(HttpCache, ETagGET_ConditionalRequest_304) { 2013 TEST(HttpCache, ETagGET_ConditionalRequest_304) {
1891 MockHttpCache cache; 2014 MockHttpCache cache;
1892 2015
1893 ScopedMockTransaction transaction(kETagGET_Transaction); 2016 ScopedMockTransaction transaction(kETagGET_Transaction);
1894 2017
1895 // write to the cache 2018 // write to the cache
1896 RunTransactionTest(cache.http_cache(), transaction); 2019 RunTransactionTest(cache.http_cache(), transaction);
1897 2020
1898 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 2021 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1899 EXPECT_EQ(0, cache.disk_cache()->open_count()); 2022 EXPECT_EQ(0, cache.disk_cache()->open_count());
1900 EXPECT_EQ(1, cache.disk_cache()->create_count()); 2023 EXPECT_EQ(1, cache.disk_cache()->create_count());
1901 2024
1902 // get the same URL again, but this time we expect it to result 2025 // Get the same URL again, but this time we expect it to result
1903 // in a conditional request. 2026 // in a conditional request.
1904 transaction.load_flags = net::LOAD_VALIDATE_CACHE; 2027 transaction.load_flags = net::LOAD_VALIDATE_CACHE;
1905 transaction.handler = ETagGet_ConditionalRequest_Handler; 2028 transaction.handler = ETagGet_ConditionalRequest_Handler;
1906 RunTransactionTest(cache.http_cache(), transaction); 2029 net::CapturingBoundNetLog log;
2030 net::LoadTimingInfo load_timing_info;
2031 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(),
2032 &load_timing_info);
1907 2033
1908 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 2034 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1909 EXPECT_EQ(1, cache.disk_cache()->open_count()); 2035 EXPECT_EQ(1, cache.disk_cache()->open_count());
1910 EXPECT_EQ(1, cache.disk_cache()->create_count()); 2036 EXPECT_EQ(1, cache.disk_cache()->create_count());
2037 TestLoadTimingNetworkRequest(load_timing_info);
1911 } 2038 }
1912 2039
1913 class RevalidationServer { 2040 class RevalidationServer {
1914 public: 2041 public:
1915 RevalidationServer() { 2042 RevalidationServer() {
1916 s_etag_used_ = false; 2043 s_etag_used_ = false;
1917 s_last_modified_used_ = false; 2044 s_last_modified_used_ = false;
1918 } 2045 }
1919 2046
1920 bool EtagUsed() { return s_etag_used_; } 2047 bool EtagUsed() { return s_etag_used_; }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1967 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" 2094 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n"
1968 "Etag: \"foopy\"\n" 2095 "Etag: \"foopy\"\n"
1969 "Cache-Control: max-age=0\n" 2096 "Cache-Control: max-age=0\n"
1970 "Vary: Foo\n"; 2097 "Vary: Foo\n";
1971 AddMockTransaction(&transaction); 2098 AddMockTransaction(&transaction);
1972 RunTransactionTest(cache.http_cache(), transaction); 2099 RunTransactionTest(cache.http_cache(), transaction);
1973 2100
1974 // Read from the cache. 2101 // Read from the cache.
1975 RevalidationServer server; 2102 RevalidationServer server;
1976 transaction.handler = server.Handler; 2103 transaction.handler = server.Handler;
1977 RunTransactionTest(cache.http_cache(), transaction); 2104 net::CapturingBoundNetLog log;
2105 net::LoadTimingInfo load_timing_info;
2106 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(),
2107 &load_timing_info);
1978 2108
1979 EXPECT_TRUE(server.EtagUsed()); 2109 EXPECT_TRUE(server.EtagUsed());
1980 EXPECT_TRUE(server.LastModifiedUsed()); 2110 EXPECT_TRUE(server.LastModifiedUsed());
1981 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 2111 EXPECT_EQ(2, cache.network_layer()->transaction_count());
1982 EXPECT_EQ(1, cache.disk_cache()->open_count()); 2112 EXPECT_EQ(1, cache.disk_cache()->open_count());
1983 EXPECT_EQ(1, cache.disk_cache()->create_count()); 2113 EXPECT_EQ(1, cache.disk_cache()->create_count());
2114 TestLoadTimingNetworkRequest(load_timing_info);
1984 RemoveMockTransaction(&transaction); 2115 RemoveMockTransaction(&transaction);
1985 } 2116 }
1986 2117
1987 // Tests revalidation after a vary mismatch if etag is present. 2118 // Tests revalidation after a vary mismatch if etag is present.
1988 TEST(HttpCache, SimpleGET_LoadValidateCache_VaryMismatch) { 2119 TEST(HttpCache, SimpleGET_LoadValidateCache_VaryMismatch) {
1989 MockHttpCache cache; 2120 MockHttpCache cache;
1990 2121
1991 // Write to the cache. 2122 // Write to the cache.
1992 MockTransaction transaction(kTypicalGET_Transaction); 2123 MockTransaction transaction(kTypicalGET_Transaction);
1993 transaction.request_headers = "Foo: bar\r\n"; 2124 transaction.request_headers = "Foo: bar\r\n";
1994 transaction.response_headers = 2125 transaction.response_headers =
1995 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n" 2126 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n"
1996 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" 2127 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n"
1997 "Etag: \"foopy\"\n" 2128 "Etag: \"foopy\"\n"
1998 "Cache-Control: max-age=0\n" 2129 "Cache-Control: max-age=0\n"
1999 "Vary: Foo\n"; 2130 "Vary: Foo\n";
2000 AddMockTransaction(&transaction); 2131 AddMockTransaction(&transaction);
2001 RunTransactionTest(cache.http_cache(), transaction); 2132 RunTransactionTest(cache.http_cache(), transaction);
2002 2133
2003 // Read from the cache and revalidate the entry. 2134 // Read from the cache and revalidate the entry.
2004 RevalidationServer server; 2135 RevalidationServer server;
2005 transaction.handler = server.Handler; 2136 transaction.handler = server.Handler;
2006 transaction.request_headers = "Foo: none\r\n"; 2137 transaction.request_headers = "Foo: none\r\n";
2007 RunTransactionTest(cache.http_cache(), transaction); 2138 net::CapturingBoundNetLog log;
2139 net::LoadTimingInfo load_timing_info;
2140 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(),
2141 &load_timing_info);
2008 2142
2009 EXPECT_TRUE(server.EtagUsed()); 2143 EXPECT_TRUE(server.EtagUsed());
2010 EXPECT_FALSE(server.LastModifiedUsed()); 2144 EXPECT_FALSE(server.LastModifiedUsed());
2011 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 2145 EXPECT_EQ(2, cache.network_layer()->transaction_count());
2012 EXPECT_EQ(1, cache.disk_cache()->open_count()); 2146 EXPECT_EQ(1, cache.disk_cache()->open_count());
2013 EXPECT_EQ(1, cache.disk_cache()->create_count()); 2147 EXPECT_EQ(1, cache.disk_cache()->create_count());
2148 TestLoadTimingNetworkRequest(load_timing_info);
2014 RemoveMockTransaction(&transaction); 2149 RemoveMockTransaction(&transaction);
2015 } 2150 }
2016 2151
2017 // Tests lack of revalidation after a vary mismatch and no etag. 2152 // Tests lack of revalidation after a vary mismatch and no etag.
2018 TEST(HttpCache, SimpleGET_LoadDontValidateCache_VaryMismatch) { 2153 TEST(HttpCache, SimpleGET_LoadDontValidateCache_VaryMismatch) {
2019 MockHttpCache cache; 2154 MockHttpCache cache;
2020 2155
2021 // Write to the cache. 2156 // Write to the cache.
2022 MockTransaction transaction(kTypicalGET_Transaction); 2157 MockTransaction transaction(kTypicalGET_Transaction);
2023 transaction.request_headers = "Foo: bar\r\n"; 2158 transaction.request_headers = "Foo: bar\r\n";
2024 transaction.response_headers = 2159 transaction.response_headers =
2025 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n" 2160 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n"
2026 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" 2161 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n"
2027 "Cache-Control: max-age=0\n" 2162 "Cache-Control: max-age=0\n"
2028 "Vary: Foo\n"; 2163 "Vary: Foo\n";
2029 AddMockTransaction(&transaction); 2164 AddMockTransaction(&transaction);
2030 RunTransactionTest(cache.http_cache(), transaction); 2165 RunTransactionTest(cache.http_cache(), transaction);
2031 2166
2032 // Read from the cache and don't revalidate the entry. 2167 // Read from the cache and don't revalidate the entry.
2033 RevalidationServer server; 2168 RevalidationServer server;
2034 transaction.handler = server.Handler; 2169 transaction.handler = server.Handler;
2035 transaction.request_headers = "Foo: none\r\n"; 2170 transaction.request_headers = "Foo: none\r\n";
2036 RunTransactionTest(cache.http_cache(), transaction); 2171 net::CapturingBoundNetLog log;
2172 net::LoadTimingInfo load_timing_info;
2173 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(),
2174 &load_timing_info);
2037 2175
2038 EXPECT_FALSE(server.EtagUsed()); 2176 EXPECT_FALSE(server.EtagUsed());
2039 EXPECT_FALSE(server.LastModifiedUsed()); 2177 EXPECT_FALSE(server.LastModifiedUsed());
2040 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 2178 EXPECT_EQ(2, cache.network_layer()->transaction_count());
2041 EXPECT_EQ(1, cache.disk_cache()->open_count()); 2179 EXPECT_EQ(1, cache.disk_cache()->open_count());
2042 EXPECT_EQ(1, cache.disk_cache()->create_count()); 2180 EXPECT_EQ(1, cache.disk_cache()->create_count());
2181 TestLoadTimingNetworkRequest(load_timing_info);
2043 RemoveMockTransaction(&transaction); 2182 RemoveMockTransaction(&transaction);
2044 } 2183 }
2045 2184
2046 static void ETagGet_UnconditionalRequest_Handler( 2185 static void ETagGet_UnconditionalRequest_Handler(
2047 const net::HttpRequestInfo* request, 2186 const net::HttpRequestInfo* request,
2048 std::string* response_status, 2187 std::string* response_status,
2049 std::string* response_headers, 2188 std::string* response_headers,
2050 std::string* response_data) { 2189 std::string* response_data) {
2051 EXPECT_FALSE( 2190 EXPECT_FALSE(
2052 request->extra_headers.HasHeader(net::HttpRequestHeaders::kIfNoneMatch)); 2191 request->extra_headers.HasHeader(net::HttpRequestHeaders::kIfNoneMatch));
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after
3233 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 3372 EXPECT_EQ(2, cache.network_layer()->transaction_count());
3234 EXPECT_EQ(2, cache.disk_cache()->open_count()); 3373 EXPECT_EQ(2, cache.disk_cache()->open_count());
3235 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3374 EXPECT_EQ(1, cache.disk_cache()->create_count());
3236 3375
3237 // Make sure we are done with the previous transaction. 3376 // Make sure we are done with the previous transaction.
3238 MessageLoop::current()->RunUntilIdle(); 3377 MessageLoop::current()->RunUntilIdle();
3239 3378
3240 // Write and read from the cache (20-59). 3379 // Write and read from the cache (20-59).
3241 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; 3380 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER;
3242 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; 3381 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 ";
3243 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); 3382 net::CapturingBoundNetLog log;
3383 net::LoadTimingInfo load_timing_info;
3384 RunTransactionTestWithResponseAndGetTiming(
3385 cache.http_cache(), transaction, &headers, log.bound(),
3386 &load_timing_info);
3244 3387
3245 Verify206Response(headers, 20, 59); 3388 Verify206Response(headers, 20, 59);
3389
3246 EXPECT_EQ(4, cache.network_layer()->transaction_count()); 3390 EXPECT_EQ(4, cache.network_layer()->transaction_count());
3247 EXPECT_EQ(3, cache.disk_cache()->open_count()); 3391 EXPECT_EQ(3, cache.disk_cache()->open_count());
3248 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3392 EXPECT_EQ(1, cache.disk_cache()->create_count());
3393 TestLoadTimingNetworkRequest(load_timing_info);
3249 3394
3250 RemoveMockTransaction(&kRangeGET_TransactionOK); 3395 RemoveMockTransaction(&kRangeGET_TransactionOK);
3251 } 3396 }
3252 3397
3253 // Tests that we can cache range requests and fetch random blocks from the 3398 // Tests that we can cache range requests and fetch random blocks from the
3254 // cache and the network, with synchronous responses. 3399 // cache and the network, with synchronous responses.
3255 TEST(HttpCache, RangeGET_SyncOK) { 3400 TEST(HttpCache, RangeGET_SyncOK) {
3256 MockHttpCache cache; 3401 MockHttpCache cache;
3257 3402
3258 MockTransaction transaction(kRangeGET_TransactionOK); 3403 MockTransaction transaction(kRangeGET_TransactionOK);
(...skipping 29 matching lines...) Expand all
3288 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 3433 EXPECT_EQ(2, cache.network_layer()->transaction_count());
3289 EXPECT_EQ(1, cache.disk_cache()->open_count()); 3434 EXPECT_EQ(1, cache.disk_cache()->open_count());
3290 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3435 EXPECT_EQ(1, cache.disk_cache()->create_count());
3291 3436
3292 // Make sure we are done with the previous transaction. 3437 // Make sure we are done with the previous transaction.
3293 MessageLoop::current()->RunUntilIdle(); 3438 MessageLoop::current()->RunUntilIdle();
3294 3439
3295 // Write and read from the cache (20-59). 3440 // Write and read from the cache (20-59).
3296 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; 3441 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER;
3297 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; 3442 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 ";
3298 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); 3443 net::CapturingBoundNetLog log;
3444 net::LoadTimingInfo load_timing_info;
3445 RunTransactionTestWithResponseAndGetTiming(
3446 cache.http_cache(), transaction, &headers, log.bound(),
3447 &load_timing_info);
3299 3448
3300 Verify206Response(headers, 20, 59); 3449 Verify206Response(headers, 20, 59);
3301 EXPECT_EQ(4, cache.network_layer()->transaction_count()); 3450 EXPECT_EQ(4, cache.network_layer()->transaction_count());
3302 EXPECT_EQ(2, cache.disk_cache()->open_count()); 3451 EXPECT_EQ(2, cache.disk_cache()->open_count());
3303 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3452 EXPECT_EQ(1, cache.disk_cache()->create_count());
3453 TestLoadTimingNetworkRequest(load_timing_info);
3304 3454
3305 RemoveMockTransaction(&transaction); 3455 RemoveMockTransaction(&transaction);
3306 } 3456 }
3307 3457
3308 // Tests that we don't revalidate an entry unless we are required to do so. 3458 // Tests that we don't revalidate an entry unless we are required to do so.
3309 TEST(HttpCache, RangeGET_Revalidate1) { 3459 TEST(HttpCache, RangeGET_Revalidate1) {
3310 MockHttpCache cache; 3460 MockHttpCache cache;
3311 std::string headers; 3461 std::string headers;
3312 3462
3313 // Write to the cache (40-49). 3463 // Write to the cache (40-49).
3314 MockTransaction transaction(kRangeGET_TransactionOK); 3464 MockTransaction transaction(kRangeGET_TransactionOK);
3315 transaction.response_headers = 3465 transaction.response_headers =
3316 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" 3466 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n"
3317 "Expires: Wed, 7 Sep 2033 21:46:42 GMT\n" // Should never expire. 3467 "Expires: Wed, 7 Sep 2033 21:46:42 GMT\n" // Should never expire.
3318 "ETag: \"foo\"\n" 3468 "ETag: \"foo\"\n"
3319 "Accept-Ranges: bytes\n" 3469 "Accept-Ranges: bytes\n"
3320 "Content-Length: 10\n"; 3470 "Content-Length: 10\n";
3321 AddMockTransaction(&transaction); 3471 AddMockTransaction(&transaction);
3322 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); 3472 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
3323 3473
3324 Verify206Response(headers, 40, 49); 3474 Verify206Response(headers, 40, 49);
3325 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 3475 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3326 EXPECT_EQ(0, cache.disk_cache()->open_count()); 3476 EXPECT_EQ(0, cache.disk_cache()->open_count());
3327 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3477 EXPECT_EQ(1, cache.disk_cache()->create_count());
3328 3478
3329 // Read from the cache (40-49). 3479 // Read from the cache (40-49).
3330 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); 3480 net::CapturingBoundNetLog log;
3481 net::LoadTimingInfo load_timing_info;
3482 RunTransactionTestWithResponseAndGetTiming(
3483 cache.http_cache(), transaction, &headers, log.bound(),
3484 &load_timing_info);
3485
3331 Verify206Response(headers, 40, 49); 3486 Verify206Response(headers, 40, 49);
3332
3333 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 3487 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3334 EXPECT_EQ(1, cache.disk_cache()->open_count()); 3488 EXPECT_EQ(1, cache.disk_cache()->open_count());
3335 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3489 EXPECT_EQ(1, cache.disk_cache()->create_count());
3490 TestLoadTimingCachedResponse(load_timing_info);
3336 3491
3337 // Read again forcing the revalidation. 3492 // Read again forcing the revalidation.
3338 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; 3493 transaction.load_flags |= net::LOAD_VALIDATE_CACHE;
3339 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); 3494 RunTransactionTestWithResponseAndGetTiming(
3495 cache.http_cache(), transaction, &headers, log.bound(),
3496 &load_timing_info);
3340 3497
3341 Verify206Response(headers, 40, 49); 3498 Verify206Response(headers, 40, 49);
3342 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 3499 EXPECT_EQ(2, cache.network_layer()->transaction_count());
3343 EXPECT_EQ(1, cache.disk_cache()->open_count()); 3500 EXPECT_EQ(1, cache.disk_cache()->open_count());
3344 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3501 EXPECT_EQ(1, cache.disk_cache()->create_count());
3502 TestLoadTimingNetworkRequest(load_timing_info);
3345 3503
3346 RemoveMockTransaction(&transaction); 3504 RemoveMockTransaction(&transaction);
3347 } 3505 }
3348 3506
3349 // Checks that we revalidate an entry when the headers say so. 3507 // Checks that we revalidate an entry when the headers say so.
3350 TEST(HttpCache, RangeGET_Revalidate2) { 3508 TEST(HttpCache, RangeGET_Revalidate2) {
3351 MockHttpCache cache; 3509 MockHttpCache cache;
3352 std::string headers; 3510 std::string headers;
3353 3511
3354 // Write to the cache (40-49). 3512 // Write to the cache (40-49).
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
3569 EXPECT_EQ(2, cache.disk_cache()->create_count()); 3727 EXPECT_EQ(2, cache.disk_cache()->create_count());
3570 3728
3571 RemoveMockTransaction(&transaction); 3729 RemoveMockTransaction(&transaction);
3572 } 3730 }
3573 3731
3574 // Tests that we can handle non-range requests when we have cached a range. 3732 // Tests that we can handle non-range requests when we have cached a range.
3575 TEST(HttpCache, GET_Previous206) { 3733 TEST(HttpCache, GET_Previous206) {
3576 MockHttpCache cache; 3734 MockHttpCache cache;
3577 AddMockTransaction(&kRangeGET_TransactionOK); 3735 AddMockTransaction(&kRangeGET_TransactionOK);
3578 std::string headers; 3736 std::string headers;
3737 net::CapturingBoundNetLog log;
3738 net::LoadTimingInfo load_timing_info;
3579 3739
3580 // Write to the cache (40-49). 3740 // Write to the cache (40-49).
3581 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, 3741 RunTransactionTestWithResponseAndGetTiming(
3582 &headers); 3742 cache.http_cache(), kRangeGET_TransactionOK, &headers, log.bound(),
3743 &load_timing_info);
3583 3744
3584 Verify206Response(headers, 40, 49); 3745 Verify206Response(headers, 40, 49);
3746
3585 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 3747 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3586 EXPECT_EQ(0, cache.disk_cache()->open_count()); 3748 EXPECT_EQ(0, cache.disk_cache()->open_count());
3587 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3749 EXPECT_EQ(1, cache.disk_cache()->create_count());
3750 TestLoadTimingNetworkRequest(load_timing_info);
3588 3751
3589 // Write and read from the cache (0-79), when not asked for a range. 3752 // Write and read from the cache (0-79), when not asked for a range.
3590 MockTransaction transaction(kRangeGET_TransactionOK); 3753 MockTransaction transaction(kRangeGET_TransactionOK);
3591 transaction.request_headers = EXTRA_HEADER; 3754 transaction.request_headers = EXTRA_HEADER;
3592 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " 3755 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 "
3593 "rg: 50-59 rg: 60-69 rg: 70-79 "; 3756 "rg: 50-59 rg: 60-69 rg: 70-79 ";
3594 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); 3757 RunTransactionTestWithResponseAndGetTiming(
3758 cache.http_cache(), transaction, &headers, log.bound(),
3759 &load_timing_info);
3595 3760
3596 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); 3761 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n"));
3597 EXPECT_EQ(3, cache.network_layer()->transaction_count()); 3762 EXPECT_EQ(3, cache.network_layer()->transaction_count());
3598 EXPECT_EQ(1, cache.disk_cache()->open_count()); 3763 EXPECT_EQ(1, cache.disk_cache()->open_count());
3599 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3764 EXPECT_EQ(1, cache.disk_cache()->create_count());
3765 TestLoadTimingNetworkRequest(load_timing_info);
3600 3766
3601 RemoveMockTransaction(&kRangeGET_TransactionOK); 3767 RemoveMockTransaction(&kRangeGET_TransactionOK);
3602 } 3768 }
3603 3769
3604 // Tests that we can handle non-range requests when we have cached the first 3770 // Tests that we can handle non-range requests when we have cached the first
3605 // part of the object and the server replies with 304 (Not Modified). 3771 // part of the object and the server replies with 304 (Not Modified).
3606 TEST(HttpCache, GET_Previous206_NotModified) { 3772 TEST(HttpCache, GET_Previous206_NotModified) {
3607 MockHttpCache cache; 3773 MockHttpCache cache;
3608 3774
3609 MockTransaction transaction(kRangeGET_TransactionOK); 3775 MockTransaction transaction(kRangeGET_TransactionOK);
3610 AddMockTransaction(&transaction); 3776 AddMockTransaction(&transaction);
3611 std::string headers; 3777 std::string headers;
3778 net::CapturingBoundNetLog log;
3779 net::LoadTimingInfo load_timing_info;
3612 3780
3613 // Write to the cache (0-9). 3781 // Write to the cache (0-9).
3614 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; 3782 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER;
3615 transaction.data = "rg: 00-09 "; 3783 transaction.data = "rg: 00-09 ";
3616 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); 3784 RunTransactionTestWithResponseAndGetTiming(
3785 cache.http_cache(), transaction, &headers, log.bound(),
3786 &load_timing_info);
3617 Verify206Response(headers, 0, 9); 3787 Verify206Response(headers, 0, 9);
3788 TestLoadTimingNetworkRequest(load_timing_info);
3618 3789
3619 // Write to the cache (70-79). 3790 // Write to the cache (70-79).
3620 transaction.request_headers = "Range: bytes = 70-79\r\n" EXTRA_HEADER; 3791 transaction.request_headers = "Range: bytes = 70-79\r\n" EXTRA_HEADER;
3621 transaction.data = "rg: 70-79 "; 3792 transaction.data = "rg: 70-79 ";
3622 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); 3793 RunTransactionTestWithResponseAndGetTiming(
3794 cache.http_cache(), transaction, &headers, log.bound(),
3795 &load_timing_info);
3623 Verify206Response(headers, 70, 79); 3796 Verify206Response(headers, 70, 79);
3624 3797
3625 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 3798 EXPECT_EQ(2, cache.network_layer()->transaction_count());
3626 EXPECT_EQ(1, cache.disk_cache()->open_count()); 3799 EXPECT_EQ(1, cache.disk_cache()->open_count());
3627 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3800 EXPECT_EQ(1, cache.disk_cache()->create_count());
3801 TestLoadTimingNetworkRequest(load_timing_info);
3628 3802
3629 // Read from the cache (0-9), write and read from cache (10 - 79). 3803 // Read from the cache (0-9), write and read from cache (10 - 79).
3630 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; 3804 transaction.load_flags |= net::LOAD_VALIDATE_CACHE;
3631 transaction.request_headers = "Foo: bar\r\n" EXTRA_HEADER; 3805 transaction.request_headers = "Foo: bar\r\n" EXTRA_HEADER;
3632 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " 3806 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 "
3633 "rg: 50-59 rg: 60-69 rg: 70-79 "; 3807 "rg: 50-59 rg: 60-69 rg: 70-79 ";
3634 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); 3808 RunTransactionTestWithResponseAndGetTiming(
3809 cache.http_cache(), transaction, &headers, log.bound(),
3810 &load_timing_info);
3635 3811
3636 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); 3812 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n"));
3813
3637 EXPECT_EQ(4, cache.network_layer()->transaction_count()); 3814 EXPECT_EQ(4, cache.network_layer()->transaction_count());
3638 EXPECT_EQ(2, cache.disk_cache()->open_count()); 3815 EXPECT_EQ(2, cache.disk_cache()->open_count());
3639 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3816 EXPECT_EQ(1, cache.disk_cache()->create_count());
3817 TestLoadTimingNetworkRequest(load_timing_info);
3640 3818
3641 RemoveMockTransaction(&transaction); 3819 RemoveMockTransaction(&transaction);
3642 } 3820 }
3643 3821
3644 // Tests that we can handle a regular request to a sparse entry, that results in 3822 // Tests that we can handle a regular request to a sparse entry, that results in
3645 // new content provided by the server (206). 3823 // new content provided by the server (206).
3646 TEST(HttpCache, GET_Previous206_NewContent) { 3824 TEST(HttpCache, GET_Previous206_NewContent) {
3647 MockHttpCache cache; 3825 MockHttpCache cache;
3648 AddMockTransaction(&kRangeGET_TransactionOK); 3826 AddMockTransaction(&kRangeGET_TransactionOK);
3649 std::string headers; 3827 std::string headers;
(...skipping 12 matching lines...) Expand all
3662 // Now we'll issue a request without any range that should result first in a 3840 // Now we'll issue a request without any range that should result first in a
3663 // 206 (when revalidating), and then in a weird standard answer: the test 3841 // 206 (when revalidating), and then in a weird standard answer: the test
3664 // server will not modify the response so we'll get the default range... a 3842 // server will not modify the response so we'll get the default range... a
3665 // real server will answer with 200. 3843 // real server will answer with 200.
3666 MockTransaction transaction2(kRangeGET_TransactionOK); 3844 MockTransaction transaction2(kRangeGET_TransactionOK);
3667 transaction2.request_headers = EXTRA_HEADER; 3845 transaction2.request_headers = EXTRA_HEADER;
3668 transaction2.load_flags |= net::LOAD_VALIDATE_CACHE; 3846 transaction2.load_flags |= net::LOAD_VALIDATE_CACHE;
3669 transaction2.data = "Not a range"; 3847 transaction2.data = "Not a range";
3670 RangeTransactionServer handler; 3848 RangeTransactionServer handler;
3671 handler.set_modified(true); 3849 handler.set_modified(true);
3672 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); 3850 net::CapturingBoundNetLog log;
3851 net::LoadTimingInfo load_timing_info;
3852 RunTransactionTestWithResponseAndGetTiming(
3853 cache.http_cache(), transaction2, &headers, log.bound(),
3854 &load_timing_info);
3673 3855
3674 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); 3856 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n"));
3675 EXPECT_EQ(3, cache.network_layer()->transaction_count()); 3857 EXPECT_EQ(3, cache.network_layer()->transaction_count());
3676 EXPECT_EQ(1, cache.disk_cache()->open_count()); 3858 EXPECT_EQ(1, cache.disk_cache()->open_count());
3677 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3859 EXPECT_EQ(1, cache.disk_cache()->create_count());
3860 TestLoadTimingNetworkRequest(load_timing_info);
3678 3861
3679 // Verify that the previous request deleted the entry. 3862 // Verify that the previous request deleted the entry.
3680 RunTransactionTest(cache.http_cache(), transaction); 3863 RunTransactionTest(cache.http_cache(), transaction);
3681 EXPECT_EQ(2, cache.disk_cache()->create_count()); 3864 EXPECT_EQ(2, cache.disk_cache()->create_count());
3682 3865
3683 RemoveMockTransaction(&transaction); 3866 RemoveMockTransaction(&transaction);
3684 } 3867 }
3685 3868
3686 // Tests that we can handle cached 206 responses that are not sparse. 3869 // Tests that we can handle cached 206 responses that are not sparse.
3687 TEST(HttpCache, GET_Previous206_NotSparse) { 3870 TEST(HttpCache, GET_Previous206_NotSparse) {
(...skipping 17 matching lines...) Expand all
3705 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500)); 3888 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500));
3706 int len = static_cast<int>(base::strlcpy(buf->data(), 3889 int len = static_cast<int>(base::strlcpy(buf->data(),
3707 kRangeGET_TransactionOK.data, 500)); 3890 kRangeGET_TransactionOK.data, 500));
3708 net::TestCompletionCallback cb; 3891 net::TestCompletionCallback cb;
3709 int rv = entry->WriteData(1, 0, buf, len, cb.callback(), true); 3892 int rv = entry->WriteData(1, 0, buf, len, cb.callback(), true);
3710 EXPECT_EQ(len, cb.GetResult(rv)); 3893 EXPECT_EQ(len, cb.GetResult(rv));
3711 entry->Close(); 3894 entry->Close();
3712 3895
3713 // Now see that we don't use the stored entry. 3896 // Now see that we don't use the stored entry.
3714 std::string headers; 3897 std::string headers;
3715 RunTransactionTestWithResponse(cache.http_cache(), kSimpleGET_Transaction, 3898 net::CapturingBoundNetLog log;
3716 &headers); 3899 net::LoadTimingInfo load_timing_info;
3900 RunTransactionTestWithResponseAndGetTiming(
3901 cache.http_cache(), kSimpleGET_Transaction, &headers, log.bound(),
3902 &load_timing_info);
3717 3903
3718 // We are expecting a 200. 3904 // We are expecting a 200.
3719 std::string expected_headers(kSimpleGET_Transaction.status); 3905 std::string expected_headers(kSimpleGET_Transaction.status);
3720 expected_headers.append("\n"); 3906 expected_headers.append("\n");
3721 expected_headers.append(kSimpleGET_Transaction.response_headers); 3907 expected_headers.append(kSimpleGET_Transaction.response_headers);
3722 EXPECT_EQ(expected_headers, headers); 3908 EXPECT_EQ(expected_headers, headers);
3723 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 3909 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3724 EXPECT_EQ(1, cache.disk_cache()->open_count()); 3910 EXPECT_EQ(1, cache.disk_cache()->open_count());
3725 EXPECT_EQ(2, cache.disk_cache()->create_count()); 3911 EXPECT_EQ(2, cache.disk_cache()->create_count());
3912 TestLoadTimingNetworkRequest(load_timing_info);
3726 } 3913 }
3727 3914
3728 // Tests that we can handle cached 206 responses that are not sparse. This time 3915 // Tests that we can handle cached 206 responses that are not sparse. This time
3729 // we issue a range request and expect to receive a range. 3916 // we issue a range request and expect to receive a range.
3730 TEST(HttpCache, RangeGET_Previous206_NotSparse_2) { 3917 TEST(HttpCache, RangeGET_Previous206_NotSparse_2) {
3731 MockHttpCache cache; 3918 MockHttpCache cache;
3732 AddMockTransaction(&kRangeGET_TransactionOK); 3919 AddMockTransaction(&kRangeGET_TransactionOK);
3733 3920
3734 // Create a disk cache entry that stores 206 headers while not being sparse. 3921 // Create a disk cache entry that stores 206 headers while not being sparse.
3735 disk_cache::Entry* entry; 3922 disk_cache::Entry* entry;
(...skipping 2063 matching lines...) Expand 10 before | Expand all | Expand 10 after
5799 trans->SetPriority(net::HIGHEST); 5986 trans->SetPriority(net::HIGHEST);
5800 // Should trigger a new network transaction and pick up the new 5987 // Should trigger a new network transaction and pick up the new
5801 // priority. 5988 // priority.
5802 ReadAndVerifyTransaction(trans.get(), transaction); 5989 ReadAndVerifyTransaction(trans.get(), transaction);
5803 5990
5804 EXPECT_EQ(net::HIGHEST, 5991 EXPECT_EQ(net::HIGHEST,
5805 cache.network_layer()->last_create_transaction_priority()); 5992 cache.network_layer()->last_create_transaction_priority());
5806 5993
5807 RemoveMockTransaction(&kRangeGET_TransactionOK); 5994 RemoveMockTransaction(&kRangeGET_TransactionOK);
5808 } 5995 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698