OLD | NEW |
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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 EXPECT_TRUE(load_timing_info.request_start_time.is_null()); | 82 EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
83 EXPECT_TRUE(load_timing_info.request_start.is_null()); | 83 EXPECT_TRUE(load_timing_info.request_start.is_null()); |
84 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); | 84 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
85 } | 85 } |
86 | 86 |
87 class DeleteCacheCompletionCallback : public net::TestCompletionCallbackBase { | 87 class DeleteCacheCompletionCallback : public net::TestCompletionCallbackBase { |
88 public: | 88 public: |
89 explicit DeleteCacheCompletionCallback(MockHttpCache* cache) | 89 explicit DeleteCacheCompletionCallback(MockHttpCache* cache) |
90 : cache_(cache), | 90 : cache_(cache), |
91 callback_(base::Bind(&DeleteCacheCompletionCallback::OnComplete, | 91 callback_(base::Bind(&DeleteCacheCompletionCallback::OnComplete, |
92 base::Unretained(this))) { | 92 base::Unretained(this))) {} |
93 } | |
94 | 93 |
95 const net::CompletionCallback& callback() const { return callback_; } | 94 const net::CompletionCallback& callback() const { return callback_; } |
96 | 95 |
97 private: | 96 private: |
98 void OnComplete(int result) { | 97 void OnComplete(int result) { |
99 delete cache_; | 98 delete cache_; |
100 SetResult(result); | 99 SetResult(result); |
101 } | 100 } |
102 | 101 |
103 MockHttpCache* cache_; | 102 MockHttpCache* cache_; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 ReadAndVerifyTransaction(trans.get(), trans_info); | 159 ReadAndVerifyTransaction(trans.get(), trans_info); |
161 | 160 |
162 if (received_bytes) | 161 if (received_bytes) |
163 *received_bytes = trans->GetTotalReceivedBytes(); | 162 *received_bytes = trans->GetTotalReceivedBytes(); |
164 } | 163 } |
165 | 164 |
166 void RunTransactionTestWithRequest(net::HttpCache* cache, | 165 void RunTransactionTestWithRequest(net::HttpCache* cache, |
167 const MockTransaction& trans_info, | 166 const MockTransaction& trans_info, |
168 const MockHttpRequest& request, | 167 const MockHttpRequest& request, |
169 net::HttpResponseInfo* response_info) { | 168 net::HttpResponseInfo* response_info) { |
170 RunTransactionTestBase(cache, trans_info, request, response_info, | 169 RunTransactionTestBase(cache, |
171 net::BoundNetLog(), NULL, NULL); | 170 trans_info, |
| 171 request, |
| 172 response_info, |
| 173 net::BoundNetLog(), |
| 174 NULL, |
| 175 NULL); |
172 } | 176 } |
173 | 177 |
174 void RunTransactionTestAndGetTiming(net::HttpCache* cache, | 178 void RunTransactionTestAndGetTiming(net::HttpCache* cache, |
175 const MockTransaction& trans_info, | 179 const MockTransaction& trans_info, |
176 const net::BoundNetLog& log, | 180 const net::BoundNetLog& log, |
177 net::LoadTimingInfo* load_timing_info) { | 181 net::LoadTimingInfo* load_timing_info) { |
178 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), | 182 RunTransactionTestBase(cache, |
179 NULL, log, load_timing_info, NULL); | 183 trans_info, |
| 184 MockHttpRequest(trans_info), |
| 185 NULL, |
| 186 log, |
| 187 load_timing_info, |
| 188 NULL); |
180 } | 189 } |
181 | 190 |
182 void RunTransactionTest(net::HttpCache* cache, | 191 void RunTransactionTest(net::HttpCache* cache, |
183 const MockTransaction& trans_info) { | 192 const MockTransaction& trans_info) { |
184 RunTransactionTestAndGetTiming(cache, trans_info, net::BoundNetLog(), NULL); | 193 RunTransactionTestAndGetTiming(cache, trans_info, net::BoundNetLog(), NULL); |
185 } | 194 } |
186 | 195 |
187 void RunTransactionTestWithResponseInfo(net::HttpCache* cache, | 196 void RunTransactionTestWithResponseInfo(net::HttpCache* cache, |
188 const MockTransaction& trans_info, | 197 const MockTransaction& trans_info, |
189 net::HttpResponseInfo* response) { | 198 net::HttpResponseInfo* response) { |
190 RunTransactionTestWithRequest(cache, trans_info, MockHttpRequest(trans_info), | 199 RunTransactionTestWithRequest( |
191 response); | 200 cache, trans_info, MockHttpRequest(trans_info), response); |
192 } | 201 } |
193 | 202 |
194 void RunTransactionTestWithResponseInfoAndGetTiming( | 203 void RunTransactionTestWithResponseInfoAndGetTiming( |
195 net::HttpCache* cache, | 204 net::HttpCache* cache, |
196 const MockTransaction& trans_info, | 205 const MockTransaction& trans_info, |
197 net::HttpResponseInfo* response, | 206 net::HttpResponseInfo* response, |
198 const net::BoundNetLog& log, | 207 const net::BoundNetLog& log, |
199 net::LoadTimingInfo* load_timing_info) { | 208 net::LoadTimingInfo* load_timing_info) { |
200 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), | 209 RunTransactionTestBase(cache, |
201 response, log, load_timing_info, NULL); | 210 trans_info, |
| 211 MockHttpRequest(trans_info), |
| 212 response, |
| 213 log, |
| 214 load_timing_info, |
| 215 NULL); |
202 } | 216 } |
203 | 217 |
204 void RunTransactionTestWithResponse(net::HttpCache* cache, | 218 void RunTransactionTestWithResponse(net::HttpCache* cache, |
205 const MockTransaction& trans_info, | 219 const MockTransaction& trans_info, |
206 std::string* response_headers) { | 220 std::string* response_headers) { |
207 net::HttpResponseInfo response; | 221 net::HttpResponseInfo response; |
208 RunTransactionTestWithResponseInfo(cache, trans_info, &response); | 222 RunTransactionTestWithResponseInfo(cache, trans_info, &response); |
209 response.headers->GetNormalizedHeaders(response_headers); | 223 response.headers->GetNormalizedHeaders(response_headers); |
210 } | 224 } |
211 | 225 |
212 void RunTransactionTestWithResponseAndGetTiming( | 226 void RunTransactionTestWithResponseAndGetTiming( |
213 net::HttpCache* cache, | 227 net::HttpCache* cache, |
214 const MockTransaction& trans_info, | 228 const MockTransaction& trans_info, |
215 std::string* response_headers, | 229 std::string* response_headers, |
216 const net::BoundNetLog& log, | 230 const net::BoundNetLog& log, |
217 net::LoadTimingInfo* load_timing_info) { | 231 net::LoadTimingInfo* load_timing_info) { |
218 net::HttpResponseInfo response; | 232 net::HttpResponseInfo response; |
219 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), | 233 RunTransactionTestBase(cache, |
220 &response, log, load_timing_info, NULL); | 234 trans_info, |
| 235 MockHttpRequest(trans_info), |
| 236 &response, |
| 237 log, |
| 238 load_timing_info, |
| 239 NULL); |
221 response.headers->GetNormalizedHeaders(response_headers); | 240 response.headers->GetNormalizedHeaders(response_headers); |
222 } | 241 } |
223 | 242 |
224 // This class provides a handler for kFastNoStoreGET_Transaction so that the | 243 // This class provides a handler for kFastNoStoreGET_Transaction so that the |
225 // no-store header can be included on demand. | 244 // no-store header can be included on demand. |
226 class FastTransactionServer { | 245 class FastTransactionServer { |
227 public: | 246 public: |
228 FastTransactionServer() { | 247 FastTransactionServer() { no_store = false; } |
229 no_store = false; | |
230 } | |
231 ~FastTransactionServer() {} | 248 ~FastTransactionServer() {} |
232 | 249 |
233 void set_no_store(bool value) { no_store = value; } | 250 void set_no_store(bool value) { no_store = value; } |
234 | 251 |
235 static void FastNoStoreHandler(const net::HttpRequestInfo* request, | 252 static void FastNoStoreHandler(const net::HttpRequestInfo* request, |
236 std::string* response_status, | 253 std::string* response_status, |
237 std::string* response_headers, | 254 std::string* response_headers, |
238 std::string* response_data) { | 255 std::string* response_data) { |
239 if (no_store) | 256 if (no_store) |
240 *response_headers = "Cache-Control: no-store\n"; | 257 *response_headers = "Cache-Control: no-store\n"; |
241 } | 258 } |
242 | 259 |
243 private: | 260 private: |
244 static bool no_store; | 261 static bool no_store; |
245 DISALLOW_COPY_AND_ASSIGN(FastTransactionServer); | 262 DISALLOW_COPY_AND_ASSIGN(FastTransactionServer); |
246 }; | 263 }; |
247 bool FastTransactionServer::no_store; | 264 bool FastTransactionServer::no_store; |
248 | 265 |
249 const MockTransaction kFastNoStoreGET_Transaction = { | 266 const MockTransaction kFastNoStoreGET_Transaction = { |
250 "http://www.google.com/nostore", | 267 "http://www.google.com/nostore", "GET", |
251 "GET", | 268 base::Time(), "", |
252 base::Time(), | 269 net::LOAD_VALIDATE_CACHE, "HTTP/1.1 200 OK", |
253 "", | 270 "Cache-Control: max-age=10000\n", base::Time(), |
254 net::LOAD_VALIDATE_CACHE, | 271 "<html><body>Google Blah Blah</body></html>", TEST_MODE_SYNC_NET_START, |
255 "HTTP/1.1 200 OK", | 272 &FastTransactionServer::FastNoStoreHandler, 0, |
256 "Cache-Control: max-age=10000\n", | 273 net::OK}; |
257 base::Time(), | |
258 "<html><body>Google Blah Blah</body></html>", | |
259 TEST_MODE_SYNC_NET_START, | |
260 &FastTransactionServer::FastNoStoreHandler, | |
261 0, | |
262 net::OK | |
263 }; | |
264 | 274 |
265 // This class provides a handler for kRangeGET_TransactionOK so that the range | 275 // This class provides a handler for kRangeGET_TransactionOK so that the range |
266 // request can be served on demand. | 276 // request can be served on demand. |
267 class RangeTransactionServer { | 277 class RangeTransactionServer { |
268 public: | 278 public: |
269 RangeTransactionServer() { | 279 RangeTransactionServer() { |
270 not_modified_ = false; | 280 not_modified_ = false; |
271 modified_ = false; | 281 modified_ = false; |
272 bad_200_ = false; | 282 bad_200_ = false; |
273 } | 283 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 } | 345 } |
336 | 346 |
337 if (not_modified_) { | 347 if (not_modified_) { |
338 response_status->assign("HTTP/1.1 304 Not Modified"); | 348 response_status->assign("HTTP/1.1 304 Not Modified"); |
339 response_data->clear(); | 349 response_data->clear(); |
340 return; | 350 return; |
341 } | 351 } |
342 | 352 |
343 std::vector<net::HttpByteRange> ranges; | 353 std::vector<net::HttpByteRange> ranges; |
344 std::string range_header; | 354 std::string range_header; |
345 if (!request->extra_headers.GetHeader( | 355 if (!request->extra_headers.GetHeader(net::HttpRequestHeaders::kRange, |
346 net::HttpRequestHeaders::kRange, &range_header) || | 356 &range_header) || |
347 !net::HttpUtil::ParseRangeHeader(range_header, &ranges) || bad_200_ || | 357 !net::HttpUtil::ParseRangeHeader(range_header, &ranges) || bad_200_ || |
348 ranges.size() != 1) { | 358 ranges.size() != 1) { |
349 // This is not a byte range request. We return 200. | 359 // This is not a byte range request. We return 200. |
350 response_status->assign("HTTP/1.1 200 OK"); | 360 response_status->assign("HTTP/1.1 200 OK"); |
351 response_headers->assign("Date: Wed, 28 Nov 2007 09:40:09 GMT"); | 361 response_headers->assign("Date: Wed, 28 Nov 2007 09:40:09 GMT"); |
352 response_data->assign("Not a range"); | 362 response_data->assign("Not a range"); |
353 return; | 363 return; |
354 } | 364 } |
355 | 365 |
356 // We can handle this range request. | 366 // We can handle this range request. |
357 net::HttpByteRange byte_range = ranges[0]; | 367 net::HttpByteRange byte_range = ranges[0]; |
358 if (byte_range.first_byte_position() > 79) { | 368 if (byte_range.first_byte_position() > 79) { |
359 response_status->assign("HTTP/1.1 416 Requested Range Not Satisfiable"); | 369 response_status->assign("HTTP/1.1 416 Requested Range Not Satisfiable"); |
360 response_data->clear(); | 370 response_data->clear(); |
361 return; | 371 return; |
362 } | 372 } |
363 | 373 |
364 EXPECT_TRUE(byte_range.ComputeBounds(80)); | 374 EXPECT_TRUE(byte_range.ComputeBounds(80)); |
365 int start = static_cast<int>(byte_range.first_byte_position()); | 375 int start = static_cast<int>(byte_range.first_byte_position()); |
366 int end = static_cast<int>(byte_range.last_byte_position()); | 376 int end = static_cast<int>(byte_range.last_byte_position()); |
367 | 377 |
368 EXPECT_LT(end, 80); | 378 EXPECT_LT(end, 80); |
369 | 379 |
370 std::string content_range = base::StringPrintf( | 380 std::string content_range = |
371 "Content-Range: bytes %d-%d/80\n", start, end); | 381 base::StringPrintf("Content-Range: bytes %d-%d/80\n", start, end); |
372 response_headers->append(content_range); | 382 response_headers->append(content_range); |
373 | 383 |
374 if (!request->extra_headers.HasHeader("If-None-Match") || modified_) { | 384 if (!request->extra_headers.HasHeader("If-None-Match") || modified_) { |
375 std::string data; | 385 std::string data; |
376 if (end == start) { | 386 if (end == start) { |
377 EXPECT_EQ(0, end % 10); | 387 EXPECT_EQ(0, end % 10); |
378 data = "r"; | 388 data = "r"; |
379 } else { | 389 } else { |
380 EXPECT_EQ(9, (end - start) % 10); | 390 EXPECT_EQ(9, (end - start) % 10); |
381 for (int block_start = start; block_start < end; block_start += 10) { | 391 for (int block_start = start; block_start < end; block_start += 10) { |
382 base::StringAppendF(&data, "rg: %02d-%02d ", | 392 base::StringAppendF( |
383 block_start, block_start + 9); | 393 &data, "rg: %02d-%02d ", block_start, block_start + 9); |
384 } | 394 } |
385 } | 395 } |
386 *response_data = data; | 396 *response_data = data; |
387 | 397 |
388 if (end - start != 9) { | 398 if (end - start != 9) { |
389 // We also have to fix content-length. | 399 // We also have to fix content-length. |
390 int len = end - start + 1; | 400 int len = end - start + 1; |
391 std::string content_length = base::StringPrintf("Content-Length: %d\n", | 401 std::string content_length = |
392 len); | 402 base::StringPrintf("Content-Length: %d\n", len); |
393 response_headers->replace(response_headers->find("Content-Length:"), | 403 response_headers->replace(response_headers->find("Content-Length:"), |
394 content_length.size(), content_length); | 404 content_length.size(), |
| 405 content_length); |
395 } | 406 } |
396 } else { | 407 } else { |
397 response_status->assign("HTTP/1.1 304 Not Modified"); | 408 response_status->assign("HTTP/1.1 304 Not Modified"); |
398 response_data->clear(); | 409 response_data->clear(); |
399 } | 410 } |
400 } | 411 } |
401 | 412 |
402 const MockTransaction kRangeGET_TransactionOK = { | 413 const MockTransaction kRangeGET_TransactionOK = { |
403 "http://www.google.com/range", | 414 "http://www.google.com/range", "GET", base::Time(), |
404 "GET", | 415 "Range: bytes = 40-49\r\n" EXTRA_HEADER, net::LOAD_NORMAL, |
405 base::Time(), | 416 "HTTP/1.1 206 Partial Content", |
406 "Range: bytes = 40-49\r\n" | 417 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
407 EXTRA_HEADER, | 418 "ETag: \"foo\"\n" |
408 net::LOAD_NORMAL, | 419 "Accept-Ranges: bytes\n" |
409 "HTTP/1.1 206 Partial Content", | 420 "Content-Length: 10\n", |
410 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 421 base::Time(), "rg: 40-49 ", TEST_MODE_NORMAL, |
411 "ETag: \"foo\"\n" | 422 &RangeTransactionServer::RangeHandler, 0, net::OK}; |
412 "Accept-Ranges: bytes\n" | |
413 "Content-Length: 10\n", | |
414 base::Time(), | |
415 "rg: 40-49 ", | |
416 TEST_MODE_NORMAL, | |
417 &RangeTransactionServer::RangeHandler, | |
418 0, | |
419 net::OK | |
420 }; | |
421 | 423 |
422 // Verifies the response headers (|response|) match a partial content | 424 // Verifies the response headers (|response|) match a partial content |
423 // response for the range starting at |start| and ending at |end|. | 425 // response for the range starting at |start| and ending at |end|. |
424 void Verify206Response(std::string response, int start, int end) { | 426 void Verify206Response(std::string response, int start, int end) { |
425 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), | 427 std::string raw_headers( |
426 response.size())); | 428 net::HttpUtil::AssembleRawHeaders(response.data(), response.size())); |
427 scoped_refptr<net::HttpResponseHeaders> headers( | 429 scoped_refptr<net::HttpResponseHeaders> headers( |
428 new net::HttpResponseHeaders(raw_headers)); | 430 new net::HttpResponseHeaders(raw_headers)); |
429 | 431 |
430 ASSERT_EQ(206, headers->response_code()); | 432 ASSERT_EQ(206, headers->response_code()); |
431 | 433 |
432 int64 range_start, range_end, object_size; | 434 int64 range_start, range_end, object_size; |
433 ASSERT_TRUE( | 435 ASSERT_TRUE(headers->GetContentRange(&range_start, &range_end, &object_size)); |
434 headers->GetContentRange(&range_start, &range_end, &object_size)); | |
435 int64 content_length = headers->GetContentLength(); | 436 int64 content_length = headers->GetContentLength(); |
436 | 437 |
437 int length = end - start + 1; | 438 int length = end - start + 1; |
438 ASSERT_EQ(length, content_length); | 439 ASSERT_EQ(length, content_length); |
439 ASSERT_EQ(start, range_start); | 440 ASSERT_EQ(start, range_start); |
440 ASSERT_EQ(end, range_end); | 441 ASSERT_EQ(end, range_end); |
441 } | 442 } |
442 | 443 |
443 // Creates a truncated entry that can be resumed using byte ranges. | 444 // Creates a truncated entry that can be resumed using byte ranges. |
444 void CreateTruncatedEntry(std::string raw_headers, MockHttpCache* cache) { | 445 void CreateTruncatedEntry(std::string raw_headers, MockHttpCache* cache) { |
445 // Create a disk cache entry that stores an incomplete resource. | 446 // Create a disk cache entry that stores an incomplete resource. |
446 disk_cache::Entry* entry; | 447 disk_cache::Entry* entry; |
447 ASSERT_TRUE(cache->CreateBackendEntry(kRangeGET_TransactionOK.url, &entry, | 448 ASSERT_TRUE( |
448 NULL)); | 449 cache->CreateBackendEntry(kRangeGET_TransactionOK.url, &entry, NULL)); |
449 | 450 |
450 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), | 451 raw_headers = |
451 raw_headers.size()); | 452 net::HttpUtil::AssembleRawHeaders(raw_headers.data(), raw_headers.size()); |
452 | 453 |
453 net::HttpResponseInfo response; | 454 net::HttpResponseInfo response; |
454 response.response_time = base::Time::Now(); | 455 response.response_time = base::Time::Now(); |
455 response.request_time = base::Time::Now(); | 456 response.request_time = base::Time::Now(); |
456 response.headers = new net::HttpResponseHeaders(raw_headers); | 457 response.headers = new net::HttpResponseHeaders(raw_headers); |
457 // Set the last argument for this to be an incomplete request. | 458 // Set the last argument for this to be an incomplete request. |
458 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, true)); | 459 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, true)); |
459 | 460 |
460 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(100)); | 461 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(100)); |
461 int len = static_cast<int>(base::strlcpy(buf->data(), | 462 int len = |
462 "rg: 00-09 rg: 10-19 ", 100)); | 463 static_cast<int>(base::strlcpy(buf->data(), "rg: 00-09 rg: 10-19 ", 100)); |
463 net::TestCompletionCallback cb; | 464 net::TestCompletionCallback cb; |
464 int rv = entry->WriteData(1, 0, buf.get(), len, cb.callback(), true); | 465 int rv = entry->WriteData(1, 0, buf.get(), len, cb.callback(), true); |
465 EXPECT_EQ(len, cb.GetResult(rv)); | 466 EXPECT_EQ(len, cb.GetResult(rv)); |
466 entry->Close(); | 467 entry->Close(); |
467 } | 468 } |
468 | 469 |
469 // Helper to represent a network HTTP response. | 470 // Helper to represent a network HTTP response. |
470 struct Response { | 471 struct Response { |
471 // Set this response into |trans|. | 472 // Set this response into |trans|. |
472 void AssignTo(MockTransaction* trans) const { | 473 void AssignTo(MockTransaction* trans) const { |
(...skipping 17 matching lines...) Expand all Loading... |
490 int result; | 491 int result; |
491 net::TestCompletionCallback callback; | 492 net::TestCompletionCallback callback; |
492 scoped_ptr<net::HttpTransaction> trans; | 493 scoped_ptr<net::HttpTransaction> trans; |
493 }; | 494 }; |
494 | 495 |
495 class FakeWebSocketHandshakeStreamCreateHelper | 496 class FakeWebSocketHandshakeStreamCreateHelper |
496 : public net::WebSocketHandshakeStreamBase::CreateHelper { | 497 : public net::WebSocketHandshakeStreamBase::CreateHelper { |
497 public: | 498 public: |
498 virtual ~FakeWebSocketHandshakeStreamCreateHelper() {} | 499 virtual ~FakeWebSocketHandshakeStreamCreateHelper() {} |
499 virtual net::WebSocketHandshakeStreamBase* CreateBasicStream( | 500 virtual net::WebSocketHandshakeStreamBase* CreateBasicStream( |
500 scoped_ptr<net::ClientSocketHandle> connect, bool using_proxy) OVERRIDE { | 501 scoped_ptr<net::ClientSocketHandle> connect, |
| 502 bool using_proxy) OVERRIDE { |
501 return NULL; | 503 return NULL; |
502 } | 504 } |
503 virtual net::WebSocketHandshakeStreamBase* CreateSpdyStream( | 505 virtual net::WebSocketHandshakeStreamBase* CreateSpdyStream( |
504 const base::WeakPtr<net::SpdySession>& session, | 506 const base::WeakPtr<net::SpdySession>& session, |
505 bool use_relative_url) OVERRIDE { | 507 bool use_relative_url) OVERRIDE { |
506 return NULL; | 508 return NULL; |
507 } | 509 } |
508 }; | 510 }; |
509 | 511 |
510 // Returns true if |entry| is not one of the log types paid attention to in this | 512 // Returns true if |entry| is not one of the log types paid attention to in this |
511 // test. Note that TYPE_HTTP_CACHE_WRITE_INFO and TYPE_HTTP_CACHE_*_DATA are | 513 // test. Note that TYPE_HTTP_CACHE_WRITE_INFO and TYPE_HTTP_CACHE_*_DATA are |
512 // ignored. | 514 // ignored. |
513 bool ShouldIgnoreLogEntry(const net::CapturingNetLog::CapturedEntry& entry) { | 515 bool ShouldIgnoreLogEntry(const net::CapturingNetLog::CapturedEntry& entry) { |
514 switch (entry.type) { | 516 switch (entry.type) { |
515 case net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND: | 517 case net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND: |
516 case net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY: | 518 case net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY: |
517 case net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY: | 519 case net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY: |
518 case net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY: | 520 case net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY: |
519 case net::NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY: | 521 case net::NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY: |
520 case net::NetLog::TYPE_HTTP_CACHE_READ_INFO: | 522 case net::NetLog::TYPE_HTTP_CACHE_READ_INFO: |
521 return false; | 523 return false; |
522 default: | 524 default: |
523 return true; | 525 return true; |
524 } | 526 } |
525 } | 527 } |
526 | 528 |
527 // Modifies |entries| to only include log entries created by the cache layer and | 529 // Modifies |entries| to only include log entries created by the cache layer and |
528 // asserted on in these tests. | 530 // asserted on in these tests. |
529 void FilterLogEntries(net::CapturingNetLog::CapturedEntryList* entries) { | 531 void FilterLogEntries(net::CapturingNetLog::CapturedEntryList* entries) { |
530 entries->erase(std::remove_if(entries->begin(), entries->end(), | 532 entries->erase( |
531 &ShouldIgnoreLogEntry), | 533 std::remove_if(entries->begin(), entries->end(), &ShouldIgnoreLogEntry), |
532 entries->end()); | 534 entries->end()); |
533 } | 535 } |
534 | 536 |
535 } // namespace | 537 } // namespace |
536 | 538 |
537 | |
538 //----------------------------------------------------------------------------- | 539 //----------------------------------------------------------------------------- |
539 // Tests. | 540 // Tests. |
540 | 541 |
541 TEST(HttpCache, CreateThenDestroy) { | 542 TEST(HttpCache, CreateThenDestroy) { |
542 MockHttpCache cache; | 543 MockHttpCache cache; |
543 | 544 |
544 scoped_ptr<net::HttpTransaction> trans; | 545 scoped_ptr<net::HttpTransaction> trans; |
545 EXPECT_EQ(net::OK, cache.CreateTransaction(&trans)); | 546 EXPECT_EQ(net::OK, cache.CreateTransaction(&trans)); |
546 ASSERT_TRUE(trans.get()); | 547 ASSERT_TRUE(trans.get()); |
547 } | 548 } |
548 | 549 |
549 TEST(HttpCache, GetBackend) { | 550 TEST(HttpCache, GetBackend) { |
550 MockHttpCache cache(net::HttpCache::DefaultBackend::InMemory(0)); | 551 MockHttpCache cache(net::HttpCache::DefaultBackend::InMemory(0)); |
551 | 552 |
552 disk_cache::Backend* backend; | 553 disk_cache::Backend* backend; |
553 net::TestCompletionCallback cb; | 554 net::TestCompletionCallback cb; |
554 // This will lazily initialize the backend. | 555 // This will lazily initialize the backend. |
555 int rv = cache.http_cache()->GetBackend(&backend, cb.callback()); | 556 int rv = cache.http_cache()->GetBackend(&backend, cb.callback()); |
556 EXPECT_EQ(net::OK, cb.GetResult(rv)); | 557 EXPECT_EQ(net::OK, cb.GetResult(rv)); |
557 } | 558 } |
558 | 559 |
559 TEST(HttpCache, SimpleGET) { | 560 TEST(HttpCache, SimpleGET) { |
560 MockHttpCache cache; | 561 MockHttpCache cache; |
561 net::CapturingBoundNetLog log; | 562 net::CapturingBoundNetLog log; |
562 net::LoadTimingInfo load_timing_info; | 563 net::LoadTimingInfo load_timing_info; |
563 | 564 |
564 // Write to the cache. | 565 // Write to the cache. |
565 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, | 566 RunTransactionTestAndGetTiming(cache.http_cache(), |
566 log.bound(), &load_timing_info); | 567 kSimpleGET_Transaction, |
| 568 log.bound(), |
| 569 &load_timing_info); |
567 | 570 |
568 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 571 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
569 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 572 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
570 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 573 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
571 TestLoadTimingNetworkRequest(load_timing_info); | 574 TestLoadTimingNetworkRequest(load_timing_info); |
572 } | 575 } |
573 | 576 |
574 TEST(HttpCache, SimpleGETNoDiskCache) { | 577 TEST(HttpCache, SimpleGETNoDiskCache) { |
575 MockHttpCache cache; | 578 MockHttpCache cache; |
576 | 579 |
577 cache.disk_cache()->set_fail_requests(); | 580 cache.disk_cache()->set_fail_requests(); |
578 | 581 |
579 net::CapturingBoundNetLog log; | 582 net::CapturingBoundNetLog log; |
580 net::LoadTimingInfo load_timing_info; | 583 net::LoadTimingInfo load_timing_info; |
581 | 584 |
582 // Read from the network, and don't use the cache. | 585 // Read from the network, and don't use the cache. |
583 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, | 586 RunTransactionTestAndGetTiming(cache.http_cache(), |
584 log.bound(), &load_timing_info); | 587 kSimpleGET_Transaction, |
| 588 log.bound(), |
| 589 &load_timing_info); |
585 | 590 |
586 // Check that the NetLog was filled as expected. | 591 // Check that the NetLog was filled as expected. |
587 // (We attempted to both Open and Create entries, but both failed). | 592 // (We attempted to both Open and Create entries, but both failed). |
588 net::CapturingNetLog::CapturedEntryList entries; | 593 net::CapturingNetLog::CapturedEntryList entries; |
589 log.GetEntries(&entries); | 594 log.GetEntries(&entries); |
590 FilterLogEntries(&entries); | 595 FilterLogEntries(&entries); |
591 | 596 |
592 EXPECT_EQ(6u, entries.size()); | 597 EXPECT_EQ(6u, entries.size()); |
593 EXPECT_TRUE(net::LogContainsBeginEvent( | 598 EXPECT_TRUE(net::LogContainsBeginEvent( |
594 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 599 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 EXPECT_EQ(3, cache.disk_cache()->create_count()); | 744 EXPECT_EQ(3, cache.disk_cache()->create_count()); |
740 } | 745 } |
741 | 746 |
742 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) { | 747 TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) { |
743 MockHttpCache cache; | 748 MockHttpCache cache; |
744 | 749 |
745 net::CapturingBoundNetLog log; | 750 net::CapturingBoundNetLog log; |
746 net::LoadTimingInfo load_timing_info; | 751 net::LoadTimingInfo load_timing_info; |
747 | 752 |
748 // Write to the cache. | 753 // Write to the cache. |
749 RunTransactionTestAndGetTiming(cache.http_cache(), kSimpleGET_Transaction, | 754 RunTransactionTestAndGetTiming(cache.http_cache(), |
750 log.bound(), &load_timing_info); | 755 kSimpleGET_Transaction, |
| 756 log.bound(), |
| 757 &load_timing_info); |
751 | 758 |
752 // Check that the NetLog was filled as expected. | 759 // Check that the NetLog was filled as expected. |
753 net::CapturingNetLog::CapturedEntryList entries; | 760 net::CapturingNetLog::CapturedEntryList entries; |
754 log.GetEntries(&entries); | 761 log.GetEntries(&entries); |
755 FilterLogEntries(&entries); | 762 FilterLogEntries(&entries); |
756 | 763 |
757 EXPECT_EQ(8u, entries.size()); | 764 EXPECT_EQ(8u, entries.size()); |
758 EXPECT_TRUE(net::LogContainsBeginEvent( | 765 EXPECT_TRUE(net::LogContainsBeginEvent( |
759 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 766 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); |
760 EXPECT_TRUE(net::LogContainsEndEvent( | 767 EXPECT_TRUE(net::LogContainsEndEvent( |
(...skipping 12 matching lines...) Expand all Loading... |
773 entries, 7, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); | 780 entries, 7, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY)); |
774 | 781 |
775 TestLoadTimingNetworkRequest(load_timing_info); | 782 TestLoadTimingNetworkRequest(load_timing_info); |
776 | 783 |
777 // Force this transaction to read from the cache. | 784 // Force this transaction to read from the cache. |
778 MockTransaction transaction(kSimpleGET_Transaction); | 785 MockTransaction transaction(kSimpleGET_Transaction); |
779 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; | 786 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; |
780 | 787 |
781 log.Clear(); | 788 log.Clear(); |
782 | 789 |
783 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), | 790 RunTransactionTestAndGetTiming( |
784 &load_timing_info); | 791 cache.http_cache(), transaction, log.bound(), &load_timing_info); |
785 | 792 |
786 // Check that the NetLog was filled as expected. | 793 // Check that the NetLog was filled as expected. |
787 log.GetEntries(&entries); | 794 log.GetEntries(&entries); |
788 FilterLogEntries(&entries); | 795 FilterLogEntries(&entries); |
789 | 796 |
790 EXPECT_EQ(8u, entries.size()); | 797 EXPECT_EQ(8u, entries.size()); |
791 EXPECT_TRUE(net::LogContainsBeginEvent( | 798 EXPECT_TRUE(net::LogContainsBeginEvent( |
792 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 799 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); |
793 EXPECT_TRUE(net::LogContainsEndEvent( | 800 EXPECT_TRUE(net::LogContainsEndEvent( |
794 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 801 entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 874 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
868 } | 875 } |
869 | 876 |
870 // Tests LOAD_PREFERRING_CACHE in the presence of vary headers. | 877 // Tests LOAD_PREFERRING_CACHE in the presence of vary headers. |
871 TEST(HttpCache, SimpleGET_LoadPreferringCache_VaryMatch) { | 878 TEST(HttpCache, SimpleGET_LoadPreferringCache_VaryMatch) { |
872 MockHttpCache cache; | 879 MockHttpCache cache; |
873 | 880 |
874 // Write to the cache. | 881 // Write to the cache. |
875 MockTransaction transaction(kSimpleGET_Transaction); | 882 MockTransaction transaction(kSimpleGET_Transaction); |
876 transaction.request_headers = "Foo: bar\r\n"; | 883 transaction.request_headers = "Foo: bar\r\n"; |
877 transaction.response_headers = "Cache-Control: max-age=10000\n" | 884 transaction.response_headers = |
878 "Vary: Foo\n"; | 885 "Cache-Control: max-age=10000\n" |
| 886 "Vary: Foo\n"; |
879 AddMockTransaction(&transaction); | 887 AddMockTransaction(&transaction); |
880 RunTransactionTest(cache.http_cache(), transaction); | 888 RunTransactionTest(cache.http_cache(), transaction); |
881 | 889 |
882 // Read from the cache. | 890 // Read from the cache. |
883 transaction.load_flags |= net::LOAD_PREFERRING_CACHE; | 891 transaction.load_flags |= net::LOAD_PREFERRING_CACHE; |
884 RunTransactionTest(cache.http_cache(), transaction); | 892 RunTransactionTest(cache.http_cache(), transaction); |
885 | 893 |
886 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 894 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
887 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 895 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
888 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 896 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
889 RemoveMockTransaction(&transaction); | 897 RemoveMockTransaction(&transaction); |
890 } | 898 } |
891 | 899 |
892 // Tests LOAD_PREFERRING_CACHE in the presence of vary headers. | 900 // Tests LOAD_PREFERRING_CACHE in the presence of vary headers. |
893 TEST(HttpCache, SimpleGET_LoadPreferringCache_VaryMismatch) { | 901 TEST(HttpCache, SimpleGET_LoadPreferringCache_VaryMismatch) { |
894 MockHttpCache cache; | 902 MockHttpCache cache; |
895 | 903 |
896 // Write to the cache. | 904 // Write to the cache. |
897 MockTransaction transaction(kSimpleGET_Transaction); | 905 MockTransaction transaction(kSimpleGET_Transaction); |
898 transaction.request_headers = "Foo: bar\r\n"; | 906 transaction.request_headers = "Foo: bar\r\n"; |
899 transaction.response_headers = "Cache-Control: max-age=10000\n" | 907 transaction.response_headers = |
900 "Vary: Foo\n"; | 908 "Cache-Control: max-age=10000\n" |
| 909 "Vary: Foo\n"; |
901 AddMockTransaction(&transaction); | 910 AddMockTransaction(&transaction); |
902 RunTransactionTest(cache.http_cache(), transaction); | 911 RunTransactionTest(cache.http_cache(), transaction); |
903 | 912 |
904 // Attempt to read from the cache... this is a vary mismatch that must reach | 913 // Attempt to read from the cache... this is a vary mismatch that must reach |
905 // the network again. | 914 // the network again. |
906 transaction.load_flags |= net::LOAD_PREFERRING_CACHE; | 915 transaction.load_flags |= net::LOAD_PREFERRING_CACHE; |
907 transaction.request_headers = "Foo: none\r\n"; | 916 transaction.request_headers = "Foo: none\r\n"; |
908 net::CapturingBoundNetLog log; | 917 net::CapturingBoundNetLog log; |
909 net::LoadTimingInfo load_timing_info; | 918 net::LoadTimingInfo load_timing_info; |
910 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), | 919 RunTransactionTestAndGetTiming( |
911 &load_timing_info); | 920 cache.http_cache(), transaction, log.bound(), &load_timing_info); |
912 | 921 |
913 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 922 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
914 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 923 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
915 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 924 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
916 TestLoadTimingNetworkRequest(load_timing_info); | 925 TestLoadTimingNetworkRequest(load_timing_info); |
917 RemoveMockTransaction(&transaction); | 926 RemoveMockTransaction(&transaction); |
918 } | 927 } |
919 | 928 |
920 // Tests that LOAD_FROM_CACHE_IF_OFFLINE returns proper response on | 929 // Tests that LOAD_FROM_CACHE_IF_OFFLINE returns proper response on |
921 // network success | 930 // network success |
922 TEST(HttpCache, SimpleGET_CacheOverride_Network) { | 931 TEST(HttpCache, SimpleGET_CacheOverride_Network) { |
923 MockHttpCache cache; | 932 MockHttpCache cache; |
924 | 933 |
925 // Prime cache. | 934 // Prime cache. |
926 MockTransaction transaction(kSimpleGET_Transaction); | 935 MockTransaction transaction(kSimpleGET_Transaction); |
927 transaction.load_flags |= net::LOAD_FROM_CACHE_IF_OFFLINE; | 936 transaction.load_flags |= net::LOAD_FROM_CACHE_IF_OFFLINE; |
928 transaction.response_headers = "Cache-Control: no-cache\n"; | 937 transaction.response_headers = "Cache-Control: no-cache\n"; |
929 | 938 |
930 AddMockTransaction(&transaction); | 939 AddMockTransaction(&transaction); |
931 RunTransactionTest(cache.http_cache(), transaction); | 940 RunTransactionTest(cache.http_cache(), transaction); |
932 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 941 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
933 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 942 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
934 RemoveMockTransaction(&transaction); | 943 RemoveMockTransaction(&transaction); |
935 | 944 |
936 // Re-run transaction; make sure the result came from the network, | 945 // Re-run transaction; make sure the result came from the network, |
937 // not the cache. | 946 // not the cache. |
938 transaction.data = "Changed data."; | 947 transaction.data = "Changed data."; |
939 AddMockTransaction(&transaction); | 948 AddMockTransaction(&transaction); |
940 net::HttpResponseInfo response_info; | 949 net::HttpResponseInfo response_info; |
941 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, | 950 RunTransactionTestWithResponseInfo( |
942 &response_info); | 951 cache.http_cache(), transaction, &response_info); |
943 | 952 |
944 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 953 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
945 EXPECT_FALSE(response_info.server_data_unavailable); | 954 EXPECT_FALSE(response_info.server_data_unavailable); |
946 EXPECT_TRUE(response_info.network_accessed); | 955 EXPECT_TRUE(response_info.network_accessed); |
947 | 956 |
948 RemoveMockTransaction(&transaction); | 957 RemoveMockTransaction(&transaction); |
949 } | 958 } |
950 | 959 |
951 // Tests that LOAD_FROM_CACHE_IF_OFFLINE returns proper response on | 960 // Tests that LOAD_FROM_CACHE_IF_OFFLINE returns proper response on |
952 // offline failure | 961 // offline failure |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 RunTransactionTest(cache.http_cache(), transaction); | 1010 RunTransactionTest(cache.http_cache(), transaction); |
1002 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1011 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
1003 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1012 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1004 RemoveMockTransaction(&transaction); | 1013 RemoveMockTransaction(&transaction); |
1005 | 1014 |
1006 // Network failure with non-offline error; should fail with that error. | 1015 // Network failure with non-offline error; should fail with that error. |
1007 transaction.return_code = net::ERR_PROXY_CONNECTION_FAILED; | 1016 transaction.return_code = net::ERR_PROXY_CONNECTION_FAILED; |
1008 AddMockTransaction(&transaction); | 1017 AddMockTransaction(&transaction); |
1009 | 1018 |
1010 net::HttpResponseInfo response_info2; | 1019 net::HttpResponseInfo response_info2; |
1011 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, | 1020 RunTransactionTestWithResponseInfo( |
1012 &response_info2); | 1021 cache.http_cache(), transaction, &response_info2); |
1013 | 1022 |
1014 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1023 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
1015 EXPECT_FALSE(response_info2.server_data_unavailable); | 1024 EXPECT_FALSE(response_info2.server_data_unavailable); |
1016 | 1025 |
1017 RemoveMockTransaction(&transaction); | 1026 RemoveMockTransaction(&transaction); |
1018 } | 1027 } |
1019 | 1028 |
1020 // Tests that was_cached was set properly on a failure, even if the cached | 1029 // Tests that was_cached was set properly on a failure, even if the cached |
1021 // response wasn't returned. | 1030 // response wasn't returned. |
1022 TEST(HttpCache, SimpleGET_CacheSignal_Failure) { | 1031 TEST(HttpCache, SimpleGET_CacheSignal_Failure) { |
(...skipping 29 matching lines...) Expand all Loading... |
1052 | 1061 |
1053 RemoveMockTransaction(&transaction); | 1062 RemoveMockTransaction(&transaction); |
1054 } | 1063 } |
1055 | 1064 |
1056 // Confirm if we have an empty cache, a read is marked as network verified. | 1065 // Confirm if we have an empty cache, a read is marked as network verified. |
1057 TEST(HttpCache, SimpleGET_NetworkAccessed_Network) { | 1066 TEST(HttpCache, SimpleGET_NetworkAccessed_Network) { |
1058 MockHttpCache cache; | 1067 MockHttpCache cache; |
1059 | 1068 |
1060 // write to the cache | 1069 // write to the cache |
1061 net::HttpResponseInfo response_info; | 1070 net::HttpResponseInfo response_info; |
1062 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, | 1071 RunTransactionTestWithResponseInfo( |
1063 &response_info); | 1072 cache.http_cache(), kSimpleGET_Transaction, &response_info); |
1064 | 1073 |
1065 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1074 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
1066 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1075 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
1067 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1076 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1068 EXPECT_TRUE(response_info.network_accessed); | 1077 EXPECT_TRUE(response_info.network_accessed); |
1069 } | 1078 } |
1070 | 1079 |
1071 // Confirm if we have a fresh entry in cache, it isn't marked as | 1080 // Confirm if we have a fresh entry in cache, it isn't marked as |
1072 // network verified. | 1081 // network verified. |
1073 TEST(HttpCache, SimpleGET_NetworkAccessed_Cache) { | 1082 TEST(HttpCache, SimpleGET_NetworkAccessed_Cache) { |
1074 MockHttpCache cache; | 1083 MockHttpCache cache; |
1075 | 1084 |
1076 // Prime cache. | 1085 // Prime cache. |
1077 MockTransaction transaction(kSimpleGET_Transaction); | 1086 MockTransaction transaction(kSimpleGET_Transaction); |
1078 | 1087 |
1079 RunTransactionTest(cache.http_cache(), transaction); | 1088 RunTransactionTest(cache.http_cache(), transaction); |
1080 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1089 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
1081 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1090 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1082 | 1091 |
1083 // Re-run transaction; make sure we don't mark the network as accessed. | 1092 // Re-run transaction; make sure we don't mark the network as accessed. |
1084 net::HttpResponseInfo response_info; | 1093 net::HttpResponseInfo response_info; |
1085 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction, | 1094 RunTransactionTestWithResponseInfo( |
1086 &response_info); | 1095 cache.http_cache(), transaction, &response_info); |
1087 | 1096 |
1088 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1097 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
1089 EXPECT_FALSE(response_info.server_data_unavailable); | 1098 EXPECT_FALSE(response_info.server_data_unavailable); |
1090 EXPECT_FALSE(response_info.network_accessed); | 1099 EXPECT_FALSE(response_info.network_accessed); |
1091 } | 1100 } |
1092 | 1101 |
1093 TEST(HttpCache, SimpleGET_LoadBypassCache) { | 1102 TEST(HttpCache, SimpleGET_LoadBypassCache) { |
1094 MockHttpCache cache; | 1103 MockHttpCache cache; |
1095 | 1104 |
1096 // Write to the cache. | 1105 // Write to the cache. |
1097 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 1106 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
1098 | 1107 |
1099 // Force this transaction to write to the cache again. | 1108 // Force this transaction to write to the cache again. |
1100 MockTransaction transaction(kSimpleGET_Transaction); | 1109 MockTransaction transaction(kSimpleGET_Transaction); |
1101 transaction.load_flags |= net::LOAD_BYPASS_CACHE; | 1110 transaction.load_flags |= net::LOAD_BYPASS_CACHE; |
1102 | 1111 |
1103 net::CapturingBoundNetLog log; | 1112 net::CapturingBoundNetLog log; |
1104 net::LoadTimingInfo load_timing_info; | 1113 net::LoadTimingInfo load_timing_info; |
1105 | 1114 |
1106 // Write to the cache. | 1115 // Write to the cache. |
1107 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), | 1116 RunTransactionTestAndGetTiming( |
1108 &load_timing_info); | 1117 cache.http_cache(), transaction, log.bound(), &load_timing_info); |
1109 | 1118 |
1110 // Check that the NetLog was filled as expected. | 1119 // Check that the NetLog was filled as expected. |
1111 net::CapturingNetLog::CapturedEntryList entries; | 1120 net::CapturingNetLog::CapturedEntryList entries; |
1112 log.GetEntries(&entries); | 1121 log.GetEntries(&entries); |
1113 FilterLogEntries(&entries); | 1122 FilterLogEntries(&entries); |
1114 | 1123 |
1115 EXPECT_EQ(8u, entries.size()); | 1124 EXPECT_EQ(8u, entries.size()); |
1116 EXPECT_TRUE(net::LogContainsBeginEvent( | 1125 EXPECT_TRUE(net::LogContainsBeginEvent( |
1117 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); | 1126 entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND)); |
1118 EXPECT_TRUE(net::LogContainsEndEvent( | 1127 EXPECT_TRUE(net::LogContainsEndEvent( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 // Read from the cache. | 1188 // Read from the cache. |
1180 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 1189 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
1181 | 1190 |
1182 // Force this transaction to validate the cache. | 1191 // Force this transaction to validate the cache. |
1183 MockTransaction transaction(kSimpleGET_Transaction); | 1192 MockTransaction transaction(kSimpleGET_Transaction); |
1184 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; | 1193 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; |
1185 | 1194 |
1186 net::HttpResponseInfo response_info; | 1195 net::HttpResponseInfo response_info; |
1187 net::CapturingBoundNetLog log; | 1196 net::CapturingBoundNetLog log; |
1188 net::LoadTimingInfo load_timing_info; | 1197 net::LoadTimingInfo load_timing_info; |
1189 RunTransactionTestWithResponseInfoAndGetTiming( | 1198 RunTransactionTestWithResponseInfoAndGetTiming(cache.http_cache(), |
1190 cache.http_cache(), transaction, &response_info, log.bound(), | 1199 transaction, |
1191 &load_timing_info); | 1200 &response_info, |
| 1201 log.bound(), |
| 1202 &load_timing_info); |
1192 | 1203 |
1193 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1204 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
1194 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 1205 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
1195 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1206 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1196 EXPECT_TRUE(response_info.network_accessed); | 1207 EXPECT_TRUE(response_info.network_accessed); |
1197 TestLoadTimingNetworkRequest(load_timing_info); | 1208 TestLoadTimingNetworkRequest(load_timing_info); |
1198 } | 1209 } |
1199 | 1210 |
1200 TEST(HttpCache, SimpleGET_LoadValidateCache_Implicit) { | 1211 TEST(HttpCache, SimpleGET_LoadValidateCache_Implicit) { |
1201 MockHttpCache cache; | 1212 MockHttpCache cache; |
1202 | 1213 |
1203 // write to the cache | 1214 // write to the cache |
1204 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 1215 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
1205 | 1216 |
1206 // read from the cache | 1217 // read from the cache |
1207 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 1218 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
1208 | 1219 |
1209 // force this transaction to validate the cache | 1220 // force this transaction to validate the cache |
1210 MockTransaction transaction(kSimpleGET_Transaction); | 1221 MockTransaction transaction(kSimpleGET_Transaction); |
1211 transaction.request_headers = "cache-control: max-age=0\r\n"; | 1222 transaction.request_headers = "cache-control: max-age=0\r\n"; |
1212 | 1223 |
1213 RunTransactionTest(cache.http_cache(), transaction); | 1224 RunTransactionTest(cache.http_cache(), transaction); |
1214 | 1225 |
1215 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1226 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
1216 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 1227 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
1217 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1228 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1218 } | 1229 } |
1219 | 1230 |
1220 static void PreserveRequestHeaders_Handler( | 1231 static void PreserveRequestHeaders_Handler(const net::HttpRequestInfo* request, |
1221 const net::HttpRequestInfo* request, | 1232 std::string* response_status, |
1222 std::string* response_status, | 1233 std::string* response_headers, |
1223 std::string* response_headers, | 1234 std::string* response_data) { |
1224 std::string* response_data) { | |
1225 EXPECT_TRUE(request->extra_headers.HasHeader(kExtraHeaderKey)); | 1235 EXPECT_TRUE(request->extra_headers.HasHeader(kExtraHeaderKey)); |
1226 } | 1236 } |
1227 | 1237 |
1228 // Tests that we don't remove extra headers for simple requests. | 1238 // Tests that we don't remove extra headers for simple requests. |
1229 TEST(HttpCache, SimpleGET_PreserveRequestHeaders) { | 1239 TEST(HttpCache, SimpleGET_PreserveRequestHeaders) { |
1230 MockHttpCache cache; | 1240 MockHttpCache cache; |
1231 | 1241 |
1232 MockTransaction transaction(kSimpleGET_Transaction); | 1242 MockTransaction transaction(kSimpleGET_Transaction); |
1233 transaction.handler = PreserveRequestHeaders_Handler; | 1243 transaction.handler = PreserveRequestHeaders_Handler; |
1234 transaction.request_headers = EXTRA_HEADER; | 1244 transaction.request_headers = EXTRA_HEADER; |
(...skipping 12 matching lines...) Expand all Loading... |
1247 | 1257 |
1248 // Tests that we don't remove extra headers for conditionalized requests. | 1258 // Tests that we don't remove extra headers for conditionalized requests. |
1249 TEST(HttpCache, ConditionalizedGET_PreserveRequestHeaders) { | 1259 TEST(HttpCache, ConditionalizedGET_PreserveRequestHeaders) { |
1250 MockHttpCache cache; | 1260 MockHttpCache cache; |
1251 | 1261 |
1252 // Write to the cache. | 1262 // Write to the cache. |
1253 RunTransactionTest(cache.http_cache(), kETagGET_Transaction); | 1263 RunTransactionTest(cache.http_cache(), kETagGET_Transaction); |
1254 | 1264 |
1255 MockTransaction transaction(kETagGET_Transaction); | 1265 MockTransaction transaction(kETagGET_Transaction); |
1256 transaction.handler = PreserveRequestHeaders_Handler; | 1266 transaction.handler = PreserveRequestHeaders_Handler; |
1257 transaction.request_headers = "If-None-Match: \"foopy\"\r\n" | 1267 transaction.request_headers = "If-None-Match: \"foopy\"\r\n" EXTRA_HEADER; |
1258 EXTRA_HEADER; | |
1259 AddMockTransaction(&transaction); | 1268 AddMockTransaction(&transaction); |
1260 | 1269 |
1261 RunTransactionTest(cache.http_cache(), transaction); | 1270 RunTransactionTest(cache.http_cache(), transaction); |
1262 | 1271 |
1263 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1272 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
1264 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 1273 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
1265 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1274 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1266 RemoveMockTransaction(&transaction); | 1275 RemoveMockTransaction(&transaction); |
1267 } | 1276 } |
1268 | 1277 |
1269 TEST(HttpCache, SimpleGET_ManyReaders) { | 1278 TEST(HttpCache, SimpleGET_ManyReaders) { |
1270 MockHttpCache cache; | 1279 MockHttpCache cache; |
1271 | 1280 |
1272 MockHttpRequest request(kSimpleGET_Transaction); | 1281 MockHttpRequest request(kSimpleGET_Transaction); |
1273 | 1282 |
1274 std::vector<Context*> context_list; | 1283 std::vector<Context*> context_list; |
1275 const int kNumTransactions = 5; | 1284 const int kNumTransactions = 5; |
1276 | 1285 |
1277 for (int i = 0; i < kNumTransactions; ++i) { | 1286 for (int i = 0; i < kNumTransactions; ++i) { |
1278 context_list.push_back(new Context()); | 1287 context_list.push_back(new Context()); |
1279 Context* c = context_list[i]; | 1288 Context* c = context_list[i]; |
1280 | 1289 |
1281 c->result = cache.CreateTransaction(&c->trans); | 1290 c->result = cache.CreateTransaction(&c->trans); |
1282 ASSERT_EQ(net::OK, c->result); | 1291 ASSERT_EQ(net::OK, c->result); |
1283 EXPECT_EQ(net::LOAD_STATE_IDLE, c->trans->GetLoadState()); | 1292 EXPECT_EQ(net::LOAD_STATE_IDLE, c->trans->GetLoadState()); |
1284 | 1293 |
1285 c->result = c->trans->Start( | 1294 c->result = |
1286 &request, c->callback.callback(), net::BoundNetLog()); | 1295 c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
1287 } | 1296 } |
1288 | 1297 |
1289 // All requests are waiting for the active entry. | 1298 // All requests are waiting for the active entry. |
1290 for (int i = 0; i < kNumTransactions; ++i) { | 1299 for (int i = 0; i < kNumTransactions; ++i) { |
1291 Context* c = context_list[i]; | 1300 Context* c = context_list[i]; |
1292 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, c->trans->GetLoadState()); | 1301 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, c->trans->GetLoadState()); |
1293 } | 1302 } |
1294 | 1303 |
1295 // Allow all requests to move from the Create queue to the active entry. | 1304 // Allow all requests to move from the Create queue to the active entry. |
1296 base::MessageLoop::current()->RunUntilIdle(); | 1305 base::MessageLoop::current()->RunUntilIdle(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1367 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1376 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
1368 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1377 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1369 | 1378 |
1370 Context* c = context_list[0]; | 1379 Context* c = context_list[0]; |
1371 ASSERT_EQ(net::ERR_IO_PENDING, c->result); | 1380 ASSERT_EQ(net::ERR_IO_PENDING, c->result); |
1372 c->result = c->callback.WaitForResult(); | 1381 c->result = c->callback.WaitForResult(); |
1373 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); | 1382 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); |
1374 | 1383 |
1375 // Now we have 2 active readers and two queued transactions. | 1384 // Now we have 2 active readers and two queued transactions. |
1376 | 1385 |
1377 EXPECT_EQ(net::LOAD_STATE_IDLE, | 1386 EXPECT_EQ(net::LOAD_STATE_IDLE, context_list[2]->trans->GetLoadState()); |
1378 context_list[2]->trans->GetLoadState()); | |
1379 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, | 1387 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, |
1380 context_list[3]->trans->GetLoadState()); | 1388 context_list[3]->trans->GetLoadState()); |
1381 | 1389 |
1382 c = context_list[1]; | 1390 c = context_list[1]; |
1383 ASSERT_EQ(net::ERR_IO_PENDING, c->result); | 1391 ASSERT_EQ(net::ERR_IO_PENDING, c->result); |
1384 c->result = c->callback.WaitForResult(); | 1392 c->result = c->callback.WaitForResult(); |
1385 if (c->result == net::OK) | 1393 if (c->result == net::OK) |
1386 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); | 1394 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); |
1387 | 1395 |
1388 // At this point we have one reader, two pending transactions and a task on | 1396 // At this point we have one reader, two pending transactions and a task on |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1475 std::vector<Context*> context_list; | 1483 std::vector<Context*> context_list; |
1476 const int kNumTransactions = 3; | 1484 const int kNumTransactions = 3; |
1477 | 1485 |
1478 for (int i = 0; i < kNumTransactions; ++i) { | 1486 for (int i = 0; i < kNumTransactions; ++i) { |
1479 context_list.push_back(new Context()); | 1487 context_list.push_back(new Context()); |
1480 Context* c = context_list[i]; | 1488 Context* c = context_list[i]; |
1481 | 1489 |
1482 c->result = cache.CreateTransaction(&c->trans); | 1490 c->result = cache.CreateTransaction(&c->trans); |
1483 ASSERT_EQ(net::OK, c->result); | 1491 ASSERT_EQ(net::OK, c->result); |
1484 | 1492 |
1485 c->result = c->trans->Start( | 1493 c->result = |
1486 &request, c->callback.callback(), net::BoundNetLog()); | 1494 c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
1487 } | 1495 } |
1488 | 1496 |
1489 // Allow all requests to move from the Create queue to the active entry. | 1497 // Allow all requests to move from the Create queue to the active entry. |
1490 base::MessageLoop::current()->RunUntilIdle(); | 1498 base::MessageLoop::current()->RunUntilIdle(); |
1491 | 1499 |
1492 // The first request should be a writer at this point, and the subsequent | 1500 // The first request should be a writer at this point, and the subsequent |
1493 // requests should be pending. | 1501 // requests should be pending. |
1494 | 1502 |
1495 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1503 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
1496 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1504 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
(...skipping 25 matching lines...) Expand all Loading... |
1522 std::vector<Context*> context_list; | 1530 std::vector<Context*> context_list; |
1523 const int kNumTransactions = 2; | 1531 const int kNumTransactions = 2; |
1524 | 1532 |
1525 for (int i = 0; i < kNumTransactions; ++i) { | 1533 for (int i = 0; i < kNumTransactions; ++i) { |
1526 context_list.push_back(new Context()); | 1534 context_list.push_back(new Context()); |
1527 Context* c = context_list[i]; | 1535 Context* c = context_list[i]; |
1528 | 1536 |
1529 c->result = cache.CreateTransaction(&c->trans); | 1537 c->result = cache.CreateTransaction(&c->trans); |
1530 ASSERT_EQ(net::OK, c->result); | 1538 ASSERT_EQ(net::OK, c->result); |
1531 | 1539 |
1532 c->result = c->trans->Start( | 1540 c->result = |
1533 &request, c->callback.callback(), net::BoundNetLog()); | 1541 c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
1534 } | 1542 } |
1535 | 1543 |
1536 // Allow all requests to move from the Create queue to the active entry. | 1544 // Allow all requests to move from the Create queue to the active entry. |
1537 base::MessageLoop::current()->RunUntilIdle(); | 1545 base::MessageLoop::current()->RunUntilIdle(); |
1538 | 1546 |
1539 // The first request should be a writer at this point, and the subsequent | 1547 // The first request should be a writer at this point, and the subsequent |
1540 // requests should be pending. | 1548 // requests should be pending. |
1541 | 1549 |
1542 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1550 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
1543 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1551 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1582 std::vector<Context*> context_list; | 1590 std::vector<Context*> context_list; |
1583 const int kNumTransactions = 5; | 1591 const int kNumTransactions = 5; |
1584 | 1592 |
1585 for (int i = 0; i < kNumTransactions; i++) { | 1593 for (int i = 0; i < kNumTransactions; i++) { |
1586 context_list.push_back(new Context()); | 1594 context_list.push_back(new Context()); |
1587 Context* c = context_list[i]; | 1595 Context* c = context_list[i]; |
1588 | 1596 |
1589 c->result = cache.CreateTransaction(&c->trans); | 1597 c->result = cache.CreateTransaction(&c->trans); |
1590 ASSERT_EQ(net::OK, c->result); | 1598 ASSERT_EQ(net::OK, c->result); |
1591 | 1599 |
1592 c->result = c->trans->Start( | 1600 c->result = |
1593 &request, c->callback.callback(), net::BoundNetLog()); | 1601 c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
1594 } | 1602 } |
1595 | 1603 |
1596 // The first request should be creating the disk cache entry and the others | 1604 // The first request should be creating the disk cache entry and the others |
1597 // should be pending. | 1605 // should be pending. |
1598 | 1606 |
1599 EXPECT_EQ(0, cache.network_layer()->transaction_count()); | 1607 EXPECT_EQ(0, cache.network_layer()->transaction_count()); |
1600 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1608 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
1601 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1609 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1602 | 1610 |
1603 // Cancel a request from the pending queue. | 1611 // Cancel a request from the pending queue. |
(...skipping 29 matching lines...) Expand all Loading... |
1633 TEST(HttpCache, SimpleGET_CancelCreate) { | 1641 TEST(HttpCache, SimpleGET_CancelCreate) { |
1634 MockHttpCache cache; | 1642 MockHttpCache cache; |
1635 | 1643 |
1636 MockHttpRequest request(kSimpleGET_Transaction); | 1644 MockHttpRequest request(kSimpleGET_Transaction); |
1637 | 1645 |
1638 Context* c = new Context(); | 1646 Context* c = new Context(); |
1639 | 1647 |
1640 c->result = cache.CreateTransaction(&c->trans); | 1648 c->result = cache.CreateTransaction(&c->trans); |
1641 ASSERT_EQ(net::OK, c->result); | 1649 ASSERT_EQ(net::OK, c->result); |
1642 | 1650 |
1643 c->result = c->trans->Start( | 1651 c->result = |
1644 &request, c->callback.callback(), net::BoundNetLog()); | 1652 c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
1645 EXPECT_EQ(net::ERR_IO_PENDING, c->result); | 1653 EXPECT_EQ(net::ERR_IO_PENDING, c->result); |
1646 | 1654 |
1647 // Release the reference that the mock disk cache keeps for this entry, so | 1655 // Release the reference that the mock disk cache keeps for this entry, so |
1648 // that we test that the http cache handles the cancellation correctly. | 1656 // that we test that the http cache handles the cancellation correctly. |
1649 cache.disk_cache()->ReleaseAll(); | 1657 cache.disk_cache()->ReleaseAll(); |
1650 delete c; | 1658 delete c; |
1651 | 1659 |
1652 base::MessageLoop::current()->RunUntilIdle(); | 1660 base::MessageLoop::current()->RunUntilIdle(); |
1653 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1661 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1654 } | 1662 } |
1655 | 1663 |
1656 // Tests that we delete/create entries even if multiple requests are queued. | 1664 // Tests that we delete/create entries even if multiple requests are queued. |
1657 TEST(HttpCache, SimpleGET_ManyWriters_BypassCache) { | 1665 TEST(HttpCache, SimpleGET_ManyWriters_BypassCache) { |
1658 MockHttpCache cache; | 1666 MockHttpCache cache; |
1659 | 1667 |
1660 MockHttpRequest request(kSimpleGET_Transaction); | 1668 MockHttpRequest request(kSimpleGET_Transaction); |
1661 request.load_flags = net::LOAD_BYPASS_CACHE; | 1669 request.load_flags = net::LOAD_BYPASS_CACHE; |
1662 | 1670 |
1663 std::vector<Context*> context_list; | 1671 std::vector<Context*> context_list; |
1664 const int kNumTransactions = 5; | 1672 const int kNumTransactions = 5; |
1665 | 1673 |
1666 for (int i = 0; i < kNumTransactions; i++) { | 1674 for (int i = 0; i < kNumTransactions; i++) { |
1667 context_list.push_back(new Context()); | 1675 context_list.push_back(new Context()); |
1668 Context* c = context_list[i]; | 1676 Context* c = context_list[i]; |
1669 | 1677 |
1670 c->result = cache.CreateTransaction(&c->trans); | 1678 c->result = cache.CreateTransaction(&c->trans); |
1671 ASSERT_EQ(net::OK, c->result); | 1679 ASSERT_EQ(net::OK, c->result); |
1672 | 1680 |
1673 c->result = c->trans->Start( | 1681 c->result = |
1674 &request, c->callback.callback(), net::BoundNetLog()); | 1682 c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
1675 } | 1683 } |
1676 | 1684 |
1677 // The first request should be deleting the disk cache entry and the others | 1685 // The first request should be deleting the disk cache entry and the others |
1678 // should be pending. | 1686 // should be pending. |
1679 | 1687 |
1680 EXPECT_EQ(0, cache.network_layer()->transaction_count()); | 1688 EXPECT_EQ(0, cache.network_layer()->transaction_count()); |
1681 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1689 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
1682 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 1690 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
1683 | 1691 |
1684 // Complete the transactions. | 1692 // Complete the transactions. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1724 trans.reset(); | 1732 trans.reset(); |
1725 | 1733 |
1726 // Make sure we pump any pending events, which should include a call to | 1734 // Make sure we pump any pending events, which should include a call to |
1727 // HttpCache::Transaction::OnCacheReadCompleted. | 1735 // HttpCache::Transaction::OnCacheReadCompleted. |
1728 base::MessageLoop::current()->RunUntilIdle(); | 1736 base::MessageLoop::current()->RunUntilIdle(); |
1729 } | 1737 } |
1730 | 1738 |
1731 // Tests that we can delete the HttpCache and deal with queued transactions | 1739 // Tests that we can delete the HttpCache and deal with queued transactions |
1732 // ("waiting for the backend" as opposed to Active or Doomed entries). | 1740 // ("waiting for the backend" as opposed to Active or Doomed entries). |
1733 TEST(HttpCache, SimpleGET_ManyWriters_DeleteCache) { | 1741 TEST(HttpCache, SimpleGET_ManyWriters_DeleteCache) { |
1734 scoped_ptr<MockHttpCache> cache(new MockHttpCache( | 1742 scoped_ptr<MockHttpCache> cache( |
1735 new MockBackendNoCbFactory())); | 1743 new MockHttpCache(new MockBackendNoCbFactory())); |
1736 | 1744 |
1737 MockHttpRequest request(kSimpleGET_Transaction); | 1745 MockHttpRequest request(kSimpleGET_Transaction); |
1738 | 1746 |
1739 std::vector<Context*> context_list; | 1747 std::vector<Context*> context_list; |
1740 const int kNumTransactions = 5; | 1748 const int kNumTransactions = 5; |
1741 | 1749 |
1742 for (int i = 0; i < kNumTransactions; i++) { | 1750 for (int i = 0; i < kNumTransactions; i++) { |
1743 context_list.push_back(new Context()); | 1751 context_list.push_back(new Context()); |
1744 Context* c = context_list[i]; | 1752 Context* c = context_list[i]; |
1745 | 1753 |
1746 c->result = cache->CreateTransaction(&c->trans); | 1754 c->result = cache->CreateTransaction(&c->trans); |
1747 ASSERT_EQ(net::OK, c->result); | 1755 ASSERT_EQ(net::OK, c->result); |
1748 | 1756 |
1749 c->result = c->trans->Start( | 1757 c->result = |
1750 &request, c->callback.callback(), net::BoundNetLog()); | 1758 c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
1751 } | 1759 } |
1752 | 1760 |
1753 // The first request should be creating the disk cache entry and the others | 1761 // The first request should be creating the disk cache entry and the others |
1754 // should be pending. | 1762 // should be pending. |
1755 | 1763 |
1756 EXPECT_EQ(0, cache->network_layer()->transaction_count()); | 1764 EXPECT_EQ(0, cache->network_layer()->transaction_count()); |
1757 EXPECT_EQ(0, cache->disk_cache()->open_count()); | 1765 EXPECT_EQ(0, cache->disk_cache()->open_count()); |
1758 EXPECT_EQ(0, cache->disk_cache()->create_count()); | 1766 EXPECT_EQ(0, cache->disk_cache()->create_count()); |
1759 | 1767 |
1760 cache.reset(); | 1768 cache.reset(); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1945 RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction); | 1953 RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction); |
1946 | 1954 |
1947 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1955 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
1948 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1956 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
1949 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1957 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1950 | 1958 |
1951 // Get the same URL again, but this time we expect it to result | 1959 // Get the same URL again, but this time we expect it to result |
1952 // in a conditional request. | 1960 // in a conditional request. |
1953 net::CapturingBoundNetLog log; | 1961 net::CapturingBoundNetLog log; |
1954 net::LoadTimingInfo load_timing_info; | 1962 net::LoadTimingInfo load_timing_info; |
1955 RunTransactionTestAndGetTiming(cache.http_cache(), kTypicalGET_Transaction, | 1963 RunTransactionTestAndGetTiming(cache.http_cache(), |
1956 log.bound(), &load_timing_info); | 1964 kTypicalGET_Transaction, |
| 1965 log.bound(), |
| 1966 &load_timing_info); |
1957 | 1967 |
1958 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1968 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
1959 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 1969 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
1960 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1970 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1961 TestLoadTimingNetworkRequest(load_timing_info); | 1971 TestLoadTimingNetworkRequest(load_timing_info); |
1962 } | 1972 } |
1963 | 1973 |
1964 static void ETagGet_ConditionalRequest_Handler( | 1974 static void ETagGet_ConditionalRequest_Handler( |
1965 const net::HttpRequestInfo* request, | 1975 const net::HttpRequestInfo* request, |
1966 std::string* response_status, | 1976 std::string* response_status, |
(...skipping 17 matching lines...) Expand all Loading... |
1984 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1994 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
1985 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1995 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
1986 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1996 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1987 | 1997 |
1988 // Get the same URL again, but this time we expect it to result | 1998 // Get the same URL again, but this time we expect it to result |
1989 // in a conditional request. | 1999 // in a conditional request. |
1990 transaction.load_flags = net::LOAD_VALIDATE_CACHE; | 2000 transaction.load_flags = net::LOAD_VALIDATE_CACHE; |
1991 transaction.handler = ETagGet_ConditionalRequest_Handler; | 2001 transaction.handler = ETagGet_ConditionalRequest_Handler; |
1992 net::CapturingBoundNetLog log; | 2002 net::CapturingBoundNetLog log; |
1993 net::LoadTimingInfo load_timing_info; | 2003 net::LoadTimingInfo load_timing_info; |
1994 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), | 2004 RunTransactionTestAndGetTiming( |
1995 &load_timing_info); | 2005 cache.http_cache(), transaction, log.bound(), &load_timing_info); |
1996 | 2006 |
1997 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2007 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
1998 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2008 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
1999 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2009 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2000 TestLoadTimingNetworkRequest(load_timing_info); | 2010 TestLoadTimingNetworkRequest(load_timing_info); |
2001 } | 2011 } |
2002 | 2012 |
2003 class RevalidationServer { | 2013 class RevalidationServer { |
2004 public: | 2014 public: |
2005 RevalidationServer() { | 2015 RevalidationServer() { |
(...skipping 14 matching lines...) Expand all Loading... |
2020 static bool s_last_modified_used_; | 2030 static bool s_last_modified_used_; |
2021 }; | 2031 }; |
2022 bool RevalidationServer::s_etag_used_ = false; | 2032 bool RevalidationServer::s_etag_used_ = false; |
2023 bool RevalidationServer::s_last_modified_used_ = false; | 2033 bool RevalidationServer::s_last_modified_used_ = false; |
2024 | 2034 |
2025 void RevalidationServer::Handler(const net::HttpRequestInfo* request, | 2035 void RevalidationServer::Handler(const net::HttpRequestInfo* request, |
2026 std::string* response_status, | 2036 std::string* response_status, |
2027 std::string* response_headers, | 2037 std::string* response_headers, |
2028 std::string* response_data) { | 2038 std::string* response_data) { |
2029 if (request->extra_headers.HasHeader(net::HttpRequestHeaders::kIfNoneMatch)) | 2039 if (request->extra_headers.HasHeader(net::HttpRequestHeaders::kIfNoneMatch)) |
2030 s_etag_used_ = true; | 2040 s_etag_used_ = true; |
2031 | 2041 |
2032 if (request->extra_headers.HasHeader( | 2042 if (request->extra_headers.HasHeader( |
2033 net::HttpRequestHeaders::kIfModifiedSince)) { | 2043 net::HttpRequestHeaders::kIfModifiedSince)) { |
2034 s_last_modified_used_ = true; | 2044 s_last_modified_used_ = true; |
2035 } | 2045 } |
2036 | 2046 |
2037 if (s_etag_used_ || s_last_modified_used_) { | 2047 if (s_etag_used_ || s_last_modified_used_) { |
2038 response_status->assign("HTTP/1.1 304 Not Modified"); | 2048 response_status->assign("HTTP/1.1 304 Not Modified"); |
2039 response_headers->assign(kTypicalGET_Transaction.response_headers); | 2049 response_headers->assign(kTypicalGET_Transaction.response_headers); |
2040 response_data->clear(); | 2050 response_data->clear(); |
2041 } else { | 2051 } else { |
2042 response_status->assign(kTypicalGET_Transaction.status); | 2052 response_status->assign(kTypicalGET_Transaction.status); |
2043 response_headers->assign(kTypicalGET_Transaction.response_headers); | 2053 response_headers->assign(kTypicalGET_Transaction.response_headers); |
2044 response_data->assign(kTypicalGET_Transaction.data); | 2054 response_data->assign(kTypicalGET_Transaction.data); |
(...skipping 14 matching lines...) Expand all Loading... |
2059 "Cache-Control: max-age=0\n" | 2069 "Cache-Control: max-age=0\n" |
2060 "Vary: Foo\n"; | 2070 "Vary: Foo\n"; |
2061 AddMockTransaction(&transaction); | 2071 AddMockTransaction(&transaction); |
2062 RunTransactionTest(cache.http_cache(), transaction); | 2072 RunTransactionTest(cache.http_cache(), transaction); |
2063 | 2073 |
2064 // Read from the cache. | 2074 // Read from the cache. |
2065 RevalidationServer server; | 2075 RevalidationServer server; |
2066 transaction.handler = server.Handler; | 2076 transaction.handler = server.Handler; |
2067 net::CapturingBoundNetLog log; | 2077 net::CapturingBoundNetLog log; |
2068 net::LoadTimingInfo load_timing_info; | 2078 net::LoadTimingInfo load_timing_info; |
2069 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), | 2079 RunTransactionTestAndGetTiming( |
2070 &load_timing_info); | 2080 cache.http_cache(), transaction, log.bound(), &load_timing_info); |
2071 | 2081 |
2072 EXPECT_TRUE(server.EtagUsed()); | 2082 EXPECT_TRUE(server.EtagUsed()); |
2073 EXPECT_TRUE(server.LastModifiedUsed()); | 2083 EXPECT_TRUE(server.LastModifiedUsed()); |
2074 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2084 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
2075 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2085 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
2076 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2086 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2077 TestLoadTimingNetworkRequest(load_timing_info); | 2087 TestLoadTimingNetworkRequest(load_timing_info); |
2078 RemoveMockTransaction(&transaction); | 2088 RemoveMockTransaction(&transaction); |
2079 } | 2089 } |
2080 | 2090 |
(...skipping 12 matching lines...) Expand all Loading... |
2093 "Vary: Foo\n"; | 2103 "Vary: Foo\n"; |
2094 AddMockTransaction(&transaction); | 2104 AddMockTransaction(&transaction); |
2095 RunTransactionTest(cache.http_cache(), transaction); | 2105 RunTransactionTest(cache.http_cache(), transaction); |
2096 | 2106 |
2097 // Read from the cache and revalidate the entry. | 2107 // Read from the cache and revalidate the entry. |
2098 RevalidationServer server; | 2108 RevalidationServer server; |
2099 transaction.handler = server.Handler; | 2109 transaction.handler = server.Handler; |
2100 transaction.request_headers = "Foo: none\r\n"; | 2110 transaction.request_headers = "Foo: none\r\n"; |
2101 net::CapturingBoundNetLog log; | 2111 net::CapturingBoundNetLog log; |
2102 net::LoadTimingInfo load_timing_info; | 2112 net::LoadTimingInfo load_timing_info; |
2103 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), | 2113 RunTransactionTestAndGetTiming( |
2104 &load_timing_info); | 2114 cache.http_cache(), transaction, log.bound(), &load_timing_info); |
2105 | 2115 |
2106 EXPECT_TRUE(server.EtagUsed()); | 2116 EXPECT_TRUE(server.EtagUsed()); |
2107 EXPECT_FALSE(server.LastModifiedUsed()); | 2117 EXPECT_FALSE(server.LastModifiedUsed()); |
2108 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2118 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
2109 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2119 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
2110 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2120 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2111 TestLoadTimingNetworkRequest(load_timing_info); | 2121 TestLoadTimingNetworkRequest(load_timing_info); |
2112 RemoveMockTransaction(&transaction); | 2122 RemoveMockTransaction(&transaction); |
2113 } | 2123 } |
2114 | 2124 |
(...skipping 11 matching lines...) Expand all Loading... |
2126 "Vary: Foo\n"; | 2136 "Vary: Foo\n"; |
2127 AddMockTransaction(&transaction); | 2137 AddMockTransaction(&transaction); |
2128 RunTransactionTest(cache.http_cache(), transaction); | 2138 RunTransactionTest(cache.http_cache(), transaction); |
2129 | 2139 |
2130 // Read from the cache and don't revalidate the entry. | 2140 // Read from the cache and don't revalidate the entry. |
2131 RevalidationServer server; | 2141 RevalidationServer server; |
2132 transaction.handler = server.Handler; | 2142 transaction.handler = server.Handler; |
2133 transaction.request_headers = "Foo: none\r\n"; | 2143 transaction.request_headers = "Foo: none\r\n"; |
2134 net::CapturingBoundNetLog log; | 2144 net::CapturingBoundNetLog log; |
2135 net::LoadTimingInfo load_timing_info; | 2145 net::LoadTimingInfo load_timing_info; |
2136 RunTransactionTestAndGetTiming(cache.http_cache(), transaction, log.bound(), | 2146 RunTransactionTestAndGetTiming( |
2137 &load_timing_info); | 2147 cache.http_cache(), transaction, log.bound(), &load_timing_info); |
2138 | 2148 |
2139 EXPECT_FALSE(server.EtagUsed()); | 2149 EXPECT_FALSE(server.EtagUsed()); |
2140 EXPECT_FALSE(server.LastModifiedUsed()); | 2150 EXPECT_FALSE(server.LastModifiedUsed()); |
2141 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2151 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
2142 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2152 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
2143 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2153 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2144 TestLoadTimingNetworkRequest(load_timing_info); | 2154 TestLoadTimingNetworkRequest(load_timing_info); |
2145 RemoveMockTransaction(&transaction); | 2155 RemoveMockTransaction(&transaction); |
2146 } | 2156 } |
2147 | 2157 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2257 const Response& net_response_1, | 2267 const Response& net_response_1, |
2258 const Response& net_response_2, | 2268 const Response& net_response_2, |
2259 const Response& cached_response_2, | 2269 const Response& cached_response_2, |
2260 const char* extra_request_headers) { | 2270 const char* extra_request_headers) { |
2261 MockHttpCache cache; | 2271 MockHttpCache cache; |
2262 | 2272 |
2263 // The URL we will be requesting. | 2273 // The URL we will be requesting. |
2264 const char* kUrl = "http://foobar.com/main.css"; | 2274 const char* kUrl = "http://foobar.com/main.css"; |
2265 | 2275 |
2266 // Junk network response. | 2276 // Junk network response. |
2267 static const Response kUnexpectedResponse = { | 2277 static const Response kUnexpectedResponse = {"HTTP/1.1 500 Unexpected", |
2268 "HTTP/1.1 500 Unexpected", | 2278 "Server: unexpected_header", |
2269 "Server: unexpected_header", | 2279 "unexpected body"}; |
2270 "unexpected body" | |
2271 }; | |
2272 | 2280 |
2273 // We will control the network layer's responses for |kUrl| using | 2281 // We will control the network layer's responses for |kUrl| using |
2274 // |mock_network_response|. | 2282 // |mock_network_response|. |
2275 MockTransaction mock_network_response = { 0 }; | 2283 MockTransaction mock_network_response = {0}; |
2276 mock_network_response.url = kUrl; | 2284 mock_network_response.url = kUrl; |
2277 AddMockTransaction(&mock_network_response); | 2285 AddMockTransaction(&mock_network_response); |
2278 | 2286 |
2279 // Request |kUrl| for the first time. It should hit the network and | 2287 // Request |kUrl| for the first time. It should hit the network and |
2280 // receive |kNetResponse1|, which it saves into the HTTP cache. | 2288 // receive |kNetResponse1|, which it saves into the HTTP cache. |
2281 | 2289 |
2282 MockTransaction request = { 0 }; | 2290 MockTransaction request = {0}; |
2283 request.url = kUrl; | 2291 request.url = kUrl; |
2284 request.method = "GET"; | 2292 request.method = "GET"; |
2285 request.request_headers = ""; | 2293 request.request_headers = ""; |
2286 | 2294 |
2287 net_response_1.AssignTo(&mock_network_response); // Network mock. | 2295 net_response_1.AssignTo(&mock_network_response); // Network mock. |
2288 net_response_1.AssignTo(&request); // Expected result. | 2296 net_response_1.AssignTo(&request); // Expected result. |
2289 | 2297 |
2290 std::string response_headers; | 2298 std::string response_headers; |
2291 RunTransactionTestWithResponse( | 2299 RunTransactionTestWithResponse( |
2292 cache.http_cache(), request, &response_headers); | 2300 cache.http_cache(), request, &response_headers); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2351 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2359 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2352 | 2360 |
2353 RemoveMockTransaction(&mock_network_response); | 2361 RemoveMockTransaction(&mock_network_response); |
2354 } | 2362 } |
2355 | 2363 |
2356 // Check that when an "if-modified-since" header is attached | 2364 // Check that when an "if-modified-since" header is attached |
2357 // to the request, the result still updates the cached entry. | 2365 // to the request, the result still updates the cached entry. |
2358 TEST(HttpCache, ConditionalizedRequestUpdatesCache1) { | 2366 TEST(HttpCache, ConditionalizedRequestUpdatesCache1) { |
2359 // First network response for |kUrl|. | 2367 // First network response for |kUrl|. |
2360 static const Response kNetResponse1 = { | 2368 static const Response kNetResponse1 = { |
2361 "HTTP/1.1 200 OK", | 2369 "HTTP/1.1 200 OK", |
2362 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 2370 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
2363 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2371 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2364 "body1" | 2372 "body1"}; |
2365 }; | |
2366 | 2373 |
2367 // Second network response for |kUrl|. | 2374 // Second network response for |kUrl|. |
2368 static const Response kNetResponse2 = { | 2375 static const Response kNetResponse2 = { |
2369 "HTTP/1.1 200 OK", | 2376 "HTTP/1.1 200 OK", |
2370 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2377 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2371 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", | 2378 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", |
2372 "body2" | 2379 "body2"}; |
2373 }; | |
2374 | 2380 |
2375 const char* extra_headers = | 2381 const char* extra_headers = |
2376 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; | 2382 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; |
2377 | 2383 |
2378 ConditionalizedRequestUpdatesCacheHelper( | 2384 ConditionalizedRequestUpdatesCacheHelper( |
2379 kNetResponse1, kNetResponse2, kNetResponse2, extra_headers); | 2385 kNetResponse1, kNetResponse2, kNetResponse2, extra_headers); |
2380 } | 2386 } |
2381 | 2387 |
2382 // Check that when an "if-none-match" header is attached | 2388 // Check that when an "if-none-match" header is attached |
2383 // to the request, the result updates the cached entry. | 2389 // to the request, the result updates the cached entry. |
2384 TEST(HttpCache, ConditionalizedRequestUpdatesCache2) { | 2390 TEST(HttpCache, ConditionalizedRequestUpdatesCache2) { |
2385 // First network response for |kUrl|. | 2391 // First network response for |kUrl|. |
2386 static const Response kNetResponse1 = { | 2392 static const Response kNetResponse1 = { |
2387 "HTTP/1.1 200 OK", | 2393 "HTTP/1.1 200 OK", |
2388 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 2394 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
2389 "Etag: \"ETAG1\"\n" | 2395 "Etag: \"ETAG1\"\n" |
2390 "Expires: Wed, 7 Sep 2033 21:46:42 GMT\n", // Should never expire. | 2396 "Expires: Wed, 7 Sep 2033 21:46:42 GMT\n", // Should never expire. |
2391 "body1" | 2397 "body1"}; |
2392 }; | |
2393 | 2398 |
2394 // Second network response for |kUrl|. | 2399 // Second network response for |kUrl|. |
2395 static const Response kNetResponse2 = { | 2400 static const Response kNetResponse2 = { |
2396 "HTTP/1.1 200 OK", | 2401 "HTTP/1.1 200 OK", |
2397 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2402 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2398 "Etag: \"ETAG2\"\n" | 2403 "Etag: \"ETAG2\"\n" |
2399 "Expires: Wed, 7 Sep 2033 21:46:42 GMT\n", // Should never expire. | 2404 "Expires: Wed, 7 Sep 2033 21:46:42 GMT\n", // Should never expire. |
2400 "body2" | 2405 "body2"}; |
2401 }; | |
2402 | 2406 |
2403 const char* extra_headers = "If-None-Match: \"ETAG1\"\r\n"; | 2407 const char* extra_headers = "If-None-Match: \"ETAG1\"\r\n"; |
2404 | 2408 |
2405 ConditionalizedRequestUpdatesCacheHelper( | 2409 ConditionalizedRequestUpdatesCacheHelper( |
2406 kNetResponse1, kNetResponse2, kNetResponse2, extra_headers); | 2410 kNetResponse1, kNetResponse2, kNetResponse2, extra_headers); |
2407 } | 2411 } |
2408 | 2412 |
2409 // Check that when an "if-modified-since" header is attached | 2413 // Check that when an "if-modified-since" header is attached |
2410 // to a request, the 304 (not modified result) result updates the cached | 2414 // to a request, the 304 (not modified result) result updates the cached |
2411 // headers, and the 304 response is returned rather than the cached response. | 2415 // headers, and the 304 response is returned rather than the cached response. |
2412 TEST(HttpCache, ConditionalizedRequestUpdatesCache3) { | 2416 TEST(HttpCache, ConditionalizedRequestUpdatesCache3) { |
2413 // First network response for |kUrl|. | 2417 // First network response for |kUrl|. |
2414 static const Response kNetResponse1 = { | 2418 static const Response kNetResponse1 = { |
2415 "HTTP/1.1 200 OK", | 2419 "HTTP/1.1 200 OK", |
2416 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 2420 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
2417 "Server: server1\n" | 2421 "Server: server1\n" |
2418 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2422 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2419 "body1" | 2423 "body1"}; |
2420 }; | |
2421 | 2424 |
2422 // Second network response for |kUrl|. | 2425 // Second network response for |kUrl|. |
2423 static const Response kNetResponse2 = { | 2426 static const Response kNetResponse2 = { |
2424 "HTTP/1.1 304 Not Modified", | 2427 "HTTP/1.1 304 Not Modified", |
2425 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2428 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2426 "Server: server2\n" | 2429 "Server: server2\n" |
2427 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2430 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2428 "" | 2431 ""}; |
2429 }; | |
2430 | 2432 |
2431 static const Response kCachedResponse2 = { | 2433 static const Response kCachedResponse2 = { |
2432 "HTTP/1.1 200 OK", | 2434 "HTTP/1.1 200 OK", |
2433 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2435 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2434 "Server: server2\n" | 2436 "Server: server2\n" |
2435 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2437 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2436 "body1" | 2438 "body1"}; |
2437 }; | |
2438 | 2439 |
2439 const char* extra_headers = | 2440 const char* extra_headers = |
2440 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; | 2441 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; |
2441 | 2442 |
2442 ConditionalizedRequestUpdatesCacheHelper( | 2443 ConditionalizedRequestUpdatesCacheHelper( |
2443 kNetResponse1, kNetResponse2, kCachedResponse2, extra_headers); | 2444 kNetResponse1, kNetResponse2, kCachedResponse2, extra_headers); |
2444 } | 2445 } |
2445 | 2446 |
2446 // Test that when doing an externally conditionalized if-modified-since | 2447 // Test that when doing an externally conditionalized if-modified-since |
2447 // and there is no corresponding cache entry, a new cache entry is NOT | 2448 // and there is no corresponding cache entry, a new cache entry is NOT |
2448 // created (304 response). | 2449 // created (304 response). |
2449 TEST(HttpCache, ConditionalizedRequestUpdatesCache4) { | 2450 TEST(HttpCache, ConditionalizedRequestUpdatesCache4) { |
2450 MockHttpCache cache; | 2451 MockHttpCache cache; |
2451 | 2452 |
2452 const char* kUrl = "http://foobar.com/main.css"; | 2453 const char* kUrl = "http://foobar.com/main.css"; |
2453 | 2454 |
2454 static const Response kNetResponse = { | 2455 static const Response kNetResponse = { |
2455 "HTTP/1.1 304 Not Modified", | 2456 "HTTP/1.1 304 Not Modified", |
2456 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2457 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2457 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2458 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2458 "" | 2459 ""}; |
2459 }; | |
2460 | 2460 |
2461 const char* kExtraRequestHeaders = | 2461 const char* kExtraRequestHeaders = |
2462 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; | 2462 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; |
2463 | 2463 |
2464 // We will control the network layer's responses for |kUrl| using | 2464 // We will control the network layer's responses for |kUrl| using |
2465 // |mock_network_response|. | 2465 // |mock_network_response|. |
2466 MockTransaction mock_network_response = { 0 }; | 2466 MockTransaction mock_network_response = {0}; |
2467 mock_network_response.url = kUrl; | 2467 mock_network_response.url = kUrl; |
2468 AddMockTransaction(&mock_network_response); | 2468 AddMockTransaction(&mock_network_response); |
2469 | 2469 |
2470 MockTransaction request = { 0 }; | 2470 MockTransaction request = {0}; |
2471 request.url = kUrl; | 2471 request.url = kUrl; |
2472 request.method = "GET"; | 2472 request.method = "GET"; |
2473 request.request_headers = kExtraRequestHeaders; | 2473 request.request_headers = kExtraRequestHeaders; |
2474 | 2474 |
2475 kNetResponse.AssignTo(&mock_network_response); // Network mock. | 2475 kNetResponse.AssignTo(&mock_network_response); // Network mock. |
2476 kNetResponse.AssignTo(&request); // Expected result. | 2476 kNetResponse.AssignTo(&request); // Expected result. |
2477 | 2477 |
2478 std::string response_headers; | 2478 std::string response_headers; |
2479 RunTransactionTestWithResponse( | 2479 RunTransactionTestWithResponse( |
2480 cache.http_cache(), request, &response_headers); | 2480 cache.http_cache(), request, &response_headers); |
2481 | 2481 |
2482 EXPECT_EQ(kNetResponse.status_and_headers(), response_headers); | 2482 EXPECT_EQ(kNetResponse.status_and_headers(), response_headers); |
2483 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2483 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
2484 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2484 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
2485 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 2485 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
2486 | 2486 |
2487 RemoveMockTransaction(&mock_network_response); | 2487 RemoveMockTransaction(&mock_network_response); |
2488 } | 2488 } |
2489 | 2489 |
2490 // Test that when doing an externally conditionalized if-modified-since | 2490 // Test that when doing an externally conditionalized if-modified-since |
2491 // and there is no corresponding cache entry, a new cache entry is NOT | 2491 // and there is no corresponding cache entry, a new cache entry is NOT |
2492 // created (200 response). | 2492 // created (200 response). |
2493 TEST(HttpCache, ConditionalizedRequestUpdatesCache5) { | 2493 TEST(HttpCache, ConditionalizedRequestUpdatesCache5) { |
2494 MockHttpCache cache; | 2494 MockHttpCache cache; |
2495 | 2495 |
2496 const char* kUrl = "http://foobar.com/main.css"; | 2496 const char* kUrl = "http://foobar.com/main.css"; |
2497 | 2497 |
2498 static const Response kNetResponse = { | 2498 static const Response kNetResponse = { |
2499 "HTTP/1.1 200 OK", | 2499 "HTTP/1.1 200 OK", |
2500 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2500 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2501 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2501 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2502 "foobar!!!" | 2502 "foobar!!!"}; |
2503 }; | |
2504 | 2503 |
2505 const char* kExtraRequestHeaders = | 2504 const char* kExtraRequestHeaders = |
2506 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; | 2505 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; |
2507 | 2506 |
2508 // We will control the network layer's responses for |kUrl| using | 2507 // We will control the network layer's responses for |kUrl| using |
2509 // |mock_network_response|. | 2508 // |mock_network_response|. |
2510 MockTransaction mock_network_response = { 0 }; | 2509 MockTransaction mock_network_response = {0}; |
2511 mock_network_response.url = kUrl; | 2510 mock_network_response.url = kUrl; |
2512 AddMockTransaction(&mock_network_response); | 2511 AddMockTransaction(&mock_network_response); |
2513 | 2512 |
2514 MockTransaction request = { 0 }; | 2513 MockTransaction request = {0}; |
2515 request.url = kUrl; | 2514 request.url = kUrl; |
2516 request.method = "GET"; | 2515 request.method = "GET"; |
2517 request.request_headers = kExtraRequestHeaders; | 2516 request.request_headers = kExtraRequestHeaders; |
2518 | 2517 |
2519 kNetResponse.AssignTo(&mock_network_response); // Network mock. | 2518 kNetResponse.AssignTo(&mock_network_response); // Network mock. |
2520 kNetResponse.AssignTo(&request); // Expected result. | 2519 kNetResponse.AssignTo(&request); // Expected result. |
2521 | 2520 |
2522 std::string response_headers; | 2521 std::string response_headers; |
2523 RunTransactionTestWithResponse( | 2522 RunTransactionTestWithResponse( |
2524 cache.http_cache(), request, &response_headers); | 2523 cache.http_cache(), request, &response_headers); |
2525 | 2524 |
2526 EXPECT_EQ(kNetResponse.status_and_headers(), response_headers); | 2525 EXPECT_EQ(kNetResponse.status_and_headers(), response_headers); |
2527 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2526 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
2528 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2527 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
2529 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 2528 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
2530 | 2529 |
2531 RemoveMockTransaction(&mock_network_response); | 2530 RemoveMockTransaction(&mock_network_response); |
2532 } | 2531 } |
2533 | 2532 |
2534 // Test that when doing an externally conditionalized if-modified-since | 2533 // Test that when doing an externally conditionalized if-modified-since |
2535 // if the date does not match the cache entry's last-modified date, | 2534 // if the date does not match the cache entry's last-modified date, |
2536 // then we do NOT use the response (304) to update the cache. | 2535 // then we do NOT use the response (304) to update the cache. |
2537 // (the if-modified-since date is 2 days AFTER the cache's modification date). | 2536 // (the if-modified-since date is 2 days AFTER the cache's modification date). |
2538 TEST(HttpCache, ConditionalizedRequestUpdatesCache6) { | 2537 TEST(HttpCache, ConditionalizedRequestUpdatesCache6) { |
2539 static const Response kNetResponse1 = { | 2538 static const Response kNetResponse1 = { |
2540 "HTTP/1.1 200 OK", | 2539 "HTTP/1.1 200 OK", |
2541 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 2540 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
2542 "Server: server1\n" | 2541 "Server: server1\n" |
2543 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2542 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2544 "body1" | 2543 "body1"}; |
2545 }; | |
2546 | 2544 |
2547 // Second network response for |kUrl|. | 2545 // Second network response for |kUrl|. |
2548 static const Response kNetResponse2 = { | 2546 static const Response kNetResponse2 = { |
2549 "HTTP/1.1 304 Not Modified", | 2547 "HTTP/1.1 304 Not Modified", |
2550 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2548 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2551 "Server: server2\n" | 2549 "Server: server2\n" |
2552 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2550 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2553 "" | 2551 ""}; |
2554 }; | |
2555 | 2552 |
2556 // This is two days in the future from the original response's last-modified | 2553 // This is two days in the future from the original response's last-modified |
2557 // date! | 2554 // date! |
2558 const char* kExtraRequestHeaders = | 2555 const char* kExtraRequestHeaders = |
2559 "If-Modified-Since: Fri, 08 Feb 2008 22:38:21 GMT\r\n"; | 2556 "If-Modified-Since: Fri, 08 Feb 2008 22:38:21 GMT\r\n"; |
2560 | 2557 |
2561 ConditionalizedRequestUpdatesCacheHelper( | 2558 ConditionalizedRequestUpdatesCacheHelper( |
2562 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); | 2559 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); |
2563 } | 2560 } |
2564 | 2561 |
2565 // Test that when doing an externally conditionalized if-none-match | 2562 // Test that when doing an externally conditionalized if-none-match |
2566 // if the etag does not match the cache entry's etag, then we do not use the | 2563 // if the etag does not match the cache entry's etag, then we do not use the |
2567 // response (304) to update the cache. | 2564 // response (304) to update the cache. |
2568 TEST(HttpCache, ConditionalizedRequestUpdatesCache7) { | 2565 TEST(HttpCache, ConditionalizedRequestUpdatesCache7) { |
2569 static const Response kNetResponse1 = { | 2566 static const Response kNetResponse1 = { |
2570 "HTTP/1.1 200 OK", | 2567 "HTTP/1.1 200 OK", |
2571 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 2568 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
2572 "Etag: \"Foo1\"\n" | 2569 "Etag: \"Foo1\"\n" |
2573 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2570 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2574 "body1" | 2571 "body1"}; |
2575 }; | |
2576 | 2572 |
2577 // Second network response for |kUrl|. | 2573 // Second network response for |kUrl|. |
2578 static const Response kNetResponse2 = { | 2574 static const Response kNetResponse2 = { |
2579 "HTTP/1.1 304 Not Modified", | 2575 "HTTP/1.1 304 Not Modified", |
2580 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2576 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2581 "Etag: \"Foo2\"\n" | 2577 "Etag: \"Foo2\"\n" |
2582 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2578 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2583 "" | 2579 ""}; |
2584 }; | |
2585 | 2580 |
2586 // Different etag from original response. | 2581 // Different etag from original response. |
2587 const char* kExtraRequestHeaders = "If-None-Match: \"Foo2\"\r\n"; | 2582 const char* kExtraRequestHeaders = "If-None-Match: \"Foo2\"\r\n"; |
2588 | 2583 |
2589 ConditionalizedRequestUpdatesCacheHelper( | 2584 ConditionalizedRequestUpdatesCacheHelper( |
2590 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); | 2585 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); |
2591 } | 2586 } |
2592 | 2587 |
2593 // Test that doing an externally conditionalized request with both if-none-match | 2588 // Test that doing an externally conditionalized request with both if-none-match |
2594 // and if-modified-since updates the cache. | 2589 // and if-modified-since updates the cache. |
2595 TEST(HttpCache, ConditionalizedRequestUpdatesCache8) { | 2590 TEST(HttpCache, ConditionalizedRequestUpdatesCache8) { |
2596 static const Response kNetResponse1 = { | 2591 static const Response kNetResponse1 = { |
2597 "HTTP/1.1 200 OK", | 2592 "HTTP/1.1 200 OK", |
2598 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 2593 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
2599 "Etag: \"Foo1\"\n" | 2594 "Etag: \"Foo1\"\n" |
2600 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2595 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2601 "body1" | 2596 "body1"}; |
2602 }; | |
2603 | 2597 |
2604 // Second network response for |kUrl|. | 2598 // Second network response for |kUrl|. |
2605 static const Response kNetResponse2 = { | 2599 static const Response kNetResponse2 = { |
2606 "HTTP/1.1 200 OK", | 2600 "HTTP/1.1 200 OK", |
2607 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2601 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2608 "Etag: \"Foo2\"\n" | 2602 "Etag: \"Foo2\"\n" |
2609 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", | 2603 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", |
2610 "body2" | 2604 "body2"}; |
2611 }; | |
2612 | 2605 |
2613 const char* kExtraRequestHeaders = | 2606 const char* kExtraRequestHeaders = |
2614 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n" | 2607 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n" |
2615 "If-None-Match: \"Foo1\"\r\n"; | 2608 "If-None-Match: \"Foo1\"\r\n"; |
2616 | 2609 |
2617 ConditionalizedRequestUpdatesCacheHelper( | 2610 ConditionalizedRequestUpdatesCacheHelper( |
2618 kNetResponse1, kNetResponse2, kNetResponse2, kExtraRequestHeaders); | 2611 kNetResponse1, kNetResponse2, kNetResponse2, kExtraRequestHeaders); |
2619 } | 2612 } |
2620 | 2613 |
2621 // Test that doing an externally conditionalized request with both if-none-match | 2614 // Test that doing an externally conditionalized request with both if-none-match |
2622 // and if-modified-since does not update the cache with only one match. | 2615 // and if-modified-since does not update the cache with only one match. |
2623 TEST(HttpCache, ConditionalizedRequestUpdatesCache9) { | 2616 TEST(HttpCache, ConditionalizedRequestUpdatesCache9) { |
2624 static const Response kNetResponse1 = { | 2617 static const Response kNetResponse1 = { |
2625 "HTTP/1.1 200 OK", | 2618 "HTTP/1.1 200 OK", |
2626 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 2619 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
2627 "Etag: \"Foo1\"\n" | 2620 "Etag: \"Foo1\"\n" |
2628 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2621 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2629 "body1" | 2622 "body1"}; |
2630 }; | |
2631 | 2623 |
2632 // Second network response for |kUrl|. | 2624 // Second network response for |kUrl|. |
2633 static const Response kNetResponse2 = { | 2625 static const Response kNetResponse2 = { |
2634 "HTTP/1.1 200 OK", | 2626 "HTTP/1.1 200 OK", |
2635 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2627 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2636 "Etag: \"Foo2\"\n" | 2628 "Etag: \"Foo2\"\n" |
2637 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", | 2629 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", |
2638 "body2" | 2630 "body2"}; |
2639 }; | |
2640 | 2631 |
2641 // The etag doesn't match what we have stored. | 2632 // The etag doesn't match what we have stored. |
2642 const char* kExtraRequestHeaders = | 2633 const char* kExtraRequestHeaders = |
2643 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n" | 2634 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n" |
2644 "If-None-Match: \"Foo2\"\r\n"; | 2635 "If-None-Match: \"Foo2\"\r\n"; |
2645 | 2636 |
2646 ConditionalizedRequestUpdatesCacheHelper( | 2637 ConditionalizedRequestUpdatesCacheHelper( |
2647 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); | 2638 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); |
2648 } | 2639 } |
2649 | 2640 |
2650 // Test that doing an externally conditionalized request with both if-none-match | 2641 // Test that doing an externally conditionalized request with both if-none-match |
2651 // and if-modified-since does not update the cache with only one match. | 2642 // and if-modified-since does not update the cache with only one match. |
2652 TEST(HttpCache, ConditionalizedRequestUpdatesCache10) { | 2643 TEST(HttpCache, ConditionalizedRequestUpdatesCache10) { |
2653 static const Response kNetResponse1 = { | 2644 static const Response kNetResponse1 = { |
2654 "HTTP/1.1 200 OK", | 2645 "HTTP/1.1 200 OK", |
2655 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 2646 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
2656 "Etag: \"Foo1\"\n" | 2647 "Etag: \"Foo1\"\n" |
2657 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2648 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2658 "body1" | 2649 "body1"}; |
2659 }; | |
2660 | 2650 |
2661 // Second network response for |kUrl|. | 2651 // Second network response for |kUrl|. |
2662 static const Response kNetResponse2 = { | 2652 static const Response kNetResponse2 = { |
2663 "HTTP/1.1 200 OK", | 2653 "HTTP/1.1 200 OK", |
2664 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2654 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2665 "Etag: \"Foo2\"\n" | 2655 "Etag: \"Foo2\"\n" |
2666 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", | 2656 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", |
2667 "body2" | 2657 "body2"}; |
2668 }; | |
2669 | 2658 |
2670 // The modification date doesn't match what we have stored. | 2659 // The modification date doesn't match what we have stored. |
2671 const char* kExtraRequestHeaders = | 2660 const char* kExtraRequestHeaders = |
2672 "If-Modified-Since: Fri, 08 Feb 2008 22:38:21 GMT\r\n" | 2661 "If-Modified-Since: Fri, 08 Feb 2008 22:38:21 GMT\r\n" |
2673 "If-None-Match: \"Foo1\"\r\n"; | 2662 "If-None-Match: \"Foo1\"\r\n"; |
2674 | 2663 |
2675 ConditionalizedRequestUpdatesCacheHelper( | 2664 ConditionalizedRequestUpdatesCacheHelper( |
2676 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); | 2665 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); |
2677 } | 2666 } |
2678 | 2667 |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3267 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3256 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3268 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 3257 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
3269 } | 3258 } |
3270 | 3259 |
3271 // Test that we skip the cache for range requests that include a validation | 3260 // Test that we skip the cache for range requests that include a validation |
3272 // header. | 3261 // header. |
3273 TEST(HttpCache, RangeGET_SkipsCache2) { | 3262 TEST(HttpCache, RangeGET_SkipsCache2) { |
3274 MockHttpCache cache; | 3263 MockHttpCache cache; |
3275 | 3264 |
3276 MockTransaction transaction(kRangeGET_Transaction); | 3265 MockTransaction transaction(kRangeGET_Transaction); |
3277 transaction.request_headers = "If-None-Match: foo\r\n" | 3266 transaction.request_headers = |
3278 EXTRA_HEADER | 3267 "If-None-Match: foo\r\n" EXTRA_HEADER "Range: bytes = 40-49\r\n"; |
3279 "Range: bytes = 40-49\r\n"; | |
3280 RunTransactionTest(cache.http_cache(), transaction); | 3268 RunTransactionTest(cache.http_cache(), transaction); |
3281 | 3269 |
3282 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3270 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3283 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3271 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3284 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 3272 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
3285 | 3273 |
3286 transaction.request_headers = | 3274 transaction.request_headers = |
3287 "If-Modified-Since: Wed, 28 Nov 2007 00:45:20 GMT\r\n" | 3275 "If-Modified-Since: Wed, 28 Nov 2007 00:45:20 GMT\r\n" EXTRA_HEADER |
3288 EXTRA_HEADER | |
3289 "Range: bytes = 40-49\r\n"; | 3276 "Range: bytes = 40-49\r\n"; |
3290 RunTransactionTest(cache.http_cache(), transaction); | 3277 RunTransactionTest(cache.http_cache(), transaction); |
3291 | 3278 |
3292 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3279 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3293 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3280 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3294 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 3281 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
3295 | 3282 |
3296 transaction.request_headers = "If-Range: bla\r\n" | 3283 transaction.request_headers = |
3297 EXTRA_HEADER | 3284 "If-Range: bla\r\n" EXTRA_HEADER "Range: bytes = 40-49\r\n"; |
3298 "Range: bytes = 40-49\r\n"; | |
3299 RunTransactionTest(cache.http_cache(), transaction); | 3285 RunTransactionTest(cache.http_cache(), transaction); |
3300 | 3286 |
3301 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 3287 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
3302 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3288 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3303 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 3289 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
3304 } | 3290 } |
3305 | 3291 |
3306 // Tests that receiving 206 for a regular request is handled correctly. | 3292 // Tests that receiving 206 for a regular request is handled correctly. |
3307 TEST(HttpCache, GET_Crazy206) { | 3293 TEST(HttpCache, GET_Crazy206) { |
3308 MockHttpCache cache; | 3294 MockHttpCache cache; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3345 } | 3331 } |
3346 | 3332 |
3347 // Tests that we don't cache partial responses that can't be validated. | 3333 // Tests that we don't cache partial responses that can't be validated. |
3348 TEST(HttpCache, RangeGET_NoStrongValidators) { | 3334 TEST(HttpCache, RangeGET_NoStrongValidators) { |
3349 MockHttpCache cache; | 3335 MockHttpCache cache; |
3350 std::string headers; | 3336 std::string headers; |
3351 | 3337 |
3352 // Attempt to write to the cache (40-49). | 3338 // Attempt to write to the cache (40-49). |
3353 MockTransaction transaction(kRangeGET_TransactionOK); | 3339 MockTransaction transaction(kRangeGET_TransactionOK); |
3354 AddMockTransaction(&transaction); | 3340 AddMockTransaction(&transaction); |
3355 transaction.response_headers = "Content-Length: 10\n" | 3341 transaction.response_headers = |
3356 "ETag: w/\"foo\"\n"; | 3342 "Content-Length: 10\n" |
| 3343 "ETag: w/\"foo\"\n"; |
3357 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 3344 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
3358 | 3345 |
3359 Verify206Response(headers, 40, 49); | 3346 Verify206Response(headers, 40, 49); |
3360 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3347 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3361 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3348 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3362 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3349 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3363 | 3350 |
3364 // Now verify that there's no cached data. | 3351 // Now verify that there's no cached data. |
3365 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 3352 RunTransactionTestWithResponse( |
3366 &headers); | 3353 cache.http_cache(), kRangeGET_TransactionOK, &headers); |
3367 | 3354 |
3368 Verify206Response(headers, 40, 49); | 3355 Verify206Response(headers, 40, 49); |
3369 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3356 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3370 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3357 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3371 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 3358 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
3372 | 3359 |
3373 RemoveMockTransaction(&transaction); | 3360 RemoveMockTransaction(&transaction); |
3374 } | 3361 } |
3375 | 3362 |
3376 // Tests that we cache partial responses that lack content-length. | 3363 // Tests that we cache partial responses that lack content-length. |
3377 TEST(HttpCache, RangeGET_NoContentLength) { | 3364 TEST(HttpCache, RangeGET_NoContentLength) { |
3378 MockHttpCache cache; | 3365 MockHttpCache cache; |
3379 std::string headers; | 3366 std::string headers; |
3380 | 3367 |
3381 // Attempt to write to the cache (40-49). | 3368 // Attempt to write to the cache (40-49). |
3382 MockTransaction transaction(kRangeGET_TransactionOK); | 3369 MockTransaction transaction(kRangeGET_TransactionOK); |
3383 AddMockTransaction(&transaction); | 3370 AddMockTransaction(&transaction); |
3384 transaction.response_headers = "ETag: \"foo\"\n" | 3371 transaction.response_headers = |
3385 "Accept-Ranges: bytes\n" | 3372 "ETag: \"foo\"\n" |
3386 "Content-Range: bytes 40-49/80\n"; | 3373 "Accept-Ranges: bytes\n" |
| 3374 "Content-Range: bytes 40-49/80\n"; |
3387 transaction.handler = NULL; | 3375 transaction.handler = NULL; |
3388 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 3376 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
3389 | 3377 |
3390 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3378 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3391 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3379 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3392 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3380 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3393 | 3381 |
3394 // Now verify that there's no cached data. | 3382 // Now verify that there's no cached data. |
3395 transaction.handler = &RangeTransactionServer::RangeHandler; | 3383 transaction.handler = &RangeTransactionServer::RangeHandler; |
3396 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 3384 RunTransactionTestWithResponse( |
3397 &headers); | 3385 cache.http_cache(), kRangeGET_TransactionOK, &headers); |
3398 | 3386 |
3399 Verify206Response(headers, 40, 49); | 3387 Verify206Response(headers, 40, 49); |
3400 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3388 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3401 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3389 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
3402 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3390 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3403 | 3391 |
3404 RemoveMockTransaction(&transaction); | 3392 RemoveMockTransaction(&transaction); |
3405 } | 3393 } |
3406 | 3394 |
3407 // Tests that we can cache range requests and fetch random blocks from the | 3395 // Tests that we can cache range requests and fetch random blocks from the |
3408 // cache and the network. | 3396 // cache and the network. |
3409 TEST(HttpCache, RangeGET_OK) { | 3397 TEST(HttpCache, RangeGET_OK) { |
3410 MockHttpCache cache; | 3398 MockHttpCache cache; |
3411 AddMockTransaction(&kRangeGET_TransactionOK); | 3399 AddMockTransaction(&kRangeGET_TransactionOK); |
3412 std::string headers; | 3400 std::string headers; |
3413 | 3401 |
3414 // Write to the cache (40-49). | 3402 // Write to the cache (40-49). |
3415 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 3403 RunTransactionTestWithResponse( |
3416 &headers); | 3404 cache.http_cache(), kRangeGET_TransactionOK, &headers); |
3417 | 3405 |
3418 Verify206Response(headers, 40, 49); | 3406 Verify206Response(headers, 40, 49); |
3419 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3407 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3420 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3408 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3421 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3409 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3422 | 3410 |
3423 // Read from the cache (40-49). | 3411 // Read from the cache (40-49). |
3424 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 3412 RunTransactionTestWithResponse( |
3425 &headers); | 3413 cache.http_cache(), kRangeGET_TransactionOK, &headers); |
3426 | 3414 |
3427 Verify206Response(headers, 40, 49); | 3415 Verify206Response(headers, 40, 49); |
3428 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3416 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3429 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3417 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
3430 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3418 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3431 | 3419 |
3432 // Make sure we are done with the previous transaction. | 3420 // Make sure we are done with the previous transaction. |
3433 base::MessageLoop::current()->RunUntilIdle(); | 3421 base::MessageLoop::current()->RunUntilIdle(); |
3434 | 3422 |
3435 // Write to the cache (30-39). | 3423 // Write to the cache (30-39). |
3436 MockTransaction transaction(kRangeGET_TransactionOK); | 3424 MockTransaction transaction(kRangeGET_TransactionOK); |
3437 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER; | 3425 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER; |
3438 transaction.data = "rg: 30-39 "; | 3426 transaction.data = "rg: 30-39 "; |
3439 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 3427 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
3440 | 3428 |
3441 Verify206Response(headers, 30, 39); | 3429 Verify206Response(headers, 30, 39); |
3442 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3430 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3443 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 3431 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
3444 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3432 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3445 | 3433 |
3446 // Make sure we are done with the previous transaction. | 3434 // Make sure we are done with the previous transaction. |
3447 base::MessageLoop::current()->RunUntilIdle(); | 3435 base::MessageLoop::current()->RunUntilIdle(); |
3448 | 3436 |
3449 // Write and read from the cache (20-59). | 3437 // Write and read from the cache (20-59). |
3450 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; | 3438 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; |
3451 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; | 3439 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; |
3452 net::CapturingBoundNetLog log; | 3440 net::CapturingBoundNetLog log; |
3453 net::LoadTimingInfo load_timing_info; | 3441 net::LoadTimingInfo load_timing_info; |
3454 RunTransactionTestWithResponseAndGetTiming( | 3442 RunTransactionTestWithResponseAndGetTiming(cache.http_cache(), |
3455 cache.http_cache(), transaction, &headers, log.bound(), | 3443 transaction, |
3456 &load_timing_info); | 3444 &headers, |
| 3445 log.bound(), |
| 3446 &load_timing_info); |
3457 | 3447 |
3458 Verify206Response(headers, 20, 59); | 3448 Verify206Response(headers, 20, 59); |
3459 EXPECT_EQ(4, cache.network_layer()->transaction_count()); | 3449 EXPECT_EQ(4, cache.network_layer()->transaction_count()); |
3460 EXPECT_EQ(3, cache.disk_cache()->open_count()); | 3450 EXPECT_EQ(3, cache.disk_cache()->open_count()); |
3461 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3451 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3462 TestLoadTimingNetworkRequest(load_timing_info); | 3452 TestLoadTimingNetworkRequest(load_timing_info); |
3463 | 3453 |
3464 RemoveMockTransaction(&kRangeGET_TransactionOK); | 3454 RemoveMockTransaction(&kRangeGET_TransactionOK); |
3465 } | 3455 } |
3466 | 3456 |
3467 // Checks that with a cache backend having Sparse IO unimplementes the cache | 3457 // Checks that with a cache backend having Sparse IO unimplementes the cache |
3468 // entry would be doomed after a range request. | 3458 // entry would be doomed after a range request. |
3469 // TODO(pasko): remove when the SimpleBackendImpl implements Sparse IO. | 3459 // TODO(pasko): remove when the SimpleBackendImpl implements Sparse IO. |
3470 TEST(HttpCache, RangeGET_SparseNotImplemented) { | 3460 TEST(HttpCache, RangeGET_SparseNotImplemented) { |
3471 MockHttpCache cache; | 3461 MockHttpCache cache; |
3472 cache.disk_cache()->set_fail_sparse_requests(); | 3462 cache.disk_cache()->set_fail_sparse_requests(); |
3473 | 3463 |
3474 // Run a cacheable request to prime the cache. | 3464 // Run a cacheable request to prime the cache. |
3475 MockTransaction transaction(kTypicalGET_Transaction); | 3465 MockTransaction transaction(kTypicalGET_Transaction); |
3476 transaction.url = kRangeGET_TransactionOK.url; | 3466 transaction.url = kRangeGET_TransactionOK.url; |
3477 AddMockTransaction(&transaction); | 3467 AddMockTransaction(&transaction); |
3478 RunTransactionTest(cache.http_cache(), transaction); | 3468 RunTransactionTest(cache.http_cache(), transaction); |
3479 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3469 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3480 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3470 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3481 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3471 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3482 | 3472 |
3483 // Verify that we added the entry. | 3473 // Verify that we added the entry. |
3484 disk_cache::Entry* entry; | 3474 disk_cache::Entry* entry; |
3485 net::TestCompletionCallback cb; | 3475 net::TestCompletionCallback cb; |
3486 int rv = cache.disk_cache()->OpenEntry(transaction.url, | 3476 int rv = |
3487 &entry, | 3477 cache.disk_cache()->OpenEntry(transaction.url, &entry, cb.callback()); |
3488 cb.callback()); | |
3489 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 3478 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
3490 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3479 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
3491 entry->Close(); | 3480 entry->Close(); |
3492 RemoveMockTransaction(&transaction); | 3481 RemoveMockTransaction(&transaction); |
3493 | 3482 |
3494 // Request the range with the backend that does not support it. | 3483 // Request the range with the backend that does not support it. |
3495 MockTransaction transaction2(kRangeGET_TransactionOK); | 3484 MockTransaction transaction2(kRangeGET_TransactionOK); |
3496 std::string headers; | 3485 std::string headers; |
3497 AddMockTransaction(&transaction2); | 3486 AddMockTransaction(&transaction2); |
3498 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); | 3487 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); |
3499 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3488 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3500 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 3489 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
3501 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 3490 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
3502 | 3491 |
3503 // Mock cache would return net::ERR_CACHE_OPEN_FAILURE on a doomed entry, even | 3492 // Mock cache would return net::ERR_CACHE_OPEN_FAILURE on a doomed entry, even |
3504 // if it was re-created later, so this effectively checks that the old data is | 3493 // if it was re-created later, so this effectively checks that the old data is |
3505 // gone. | 3494 // gone. |
3506 disk_cache::Entry* entry2; | 3495 disk_cache::Entry* entry2; |
3507 rv = cache.disk_cache()->OpenEntry(transaction2.url, | 3496 rv = cache.disk_cache()->OpenEntry(transaction2.url, &entry2, cb.callback()); |
3508 &entry2, | |
3509 cb.callback()); | |
3510 ASSERT_EQ(net::ERR_CACHE_OPEN_FAILURE, cb.GetResult(rv)); | 3497 ASSERT_EQ(net::ERR_CACHE_OPEN_FAILURE, cb.GetResult(rv)); |
3511 RemoveMockTransaction(&transaction2); | 3498 RemoveMockTransaction(&transaction2); |
3512 } | 3499 } |
3513 | 3500 |
3514 TEST(HttpCache, RangeGET_SparseNotImplementedOnEmptyCache) { | 3501 TEST(HttpCache, RangeGET_SparseNotImplementedOnEmptyCache) { |
3515 MockHttpCache cache; | 3502 MockHttpCache cache; |
3516 cache.disk_cache()->set_fail_sparse_requests(); | 3503 cache.disk_cache()->set_fail_sparse_requests(); |
3517 | 3504 |
3518 // Request the range with the backend that does not support it. | 3505 // Request the range with the backend that does not support it. |
3519 MockTransaction transaction(kRangeGET_TransactionOK); | 3506 MockTransaction transaction(kRangeGET_TransactionOK); |
3520 std::string headers; | 3507 std::string headers; |
3521 AddMockTransaction(&transaction); | 3508 AddMockTransaction(&transaction); |
3522 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 3509 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
3523 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3510 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3524 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3511 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3525 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3512 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3526 | 3513 |
3527 // Mock cache would return net::ERR_CACHE_OPEN_FAILURE on a doomed entry, even | 3514 // Mock cache would return net::ERR_CACHE_OPEN_FAILURE on a doomed entry, even |
3528 // if it was re-created later, so this effectively checks that the old data is | 3515 // if it was re-created later, so this effectively checks that the old data is |
3529 // gone as a result of a failed range write. | 3516 // gone as a result of a failed range write. |
3530 disk_cache::Entry* entry; | 3517 disk_cache::Entry* entry; |
3531 net::TestCompletionCallback cb; | 3518 net::TestCompletionCallback cb; |
3532 int rv = cache.disk_cache()->OpenEntry(transaction.url, | 3519 int rv = |
3533 &entry, | 3520 cache.disk_cache()->OpenEntry(transaction.url, &entry, cb.callback()); |
3534 cb.callback()); | |
3535 ASSERT_EQ(net::ERR_CACHE_OPEN_FAILURE, cb.GetResult(rv)); | 3521 ASSERT_EQ(net::ERR_CACHE_OPEN_FAILURE, cb.GetResult(rv)); |
3536 RemoveMockTransaction(&transaction); | 3522 RemoveMockTransaction(&transaction); |
3537 } | 3523 } |
3538 | 3524 |
3539 // Tests that we can cache range requests and fetch random blocks from the | 3525 // Tests that we can cache range requests and fetch random blocks from the |
3540 // cache and the network, with synchronous responses. | 3526 // cache and the network, with synchronous responses. |
3541 TEST(HttpCache, RangeGET_SyncOK) { | 3527 TEST(HttpCache, RangeGET_SyncOK) { |
3542 MockHttpCache cache; | 3528 MockHttpCache cache; |
3543 | 3529 |
3544 MockTransaction transaction(kRangeGET_TransactionOK); | 3530 MockTransaction transaction(kRangeGET_TransactionOK); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3576 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3562 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3577 | 3563 |
3578 // Make sure we are done with the previous transaction. | 3564 // Make sure we are done with the previous transaction. |
3579 base::MessageLoop::current()->RunUntilIdle(); | 3565 base::MessageLoop::current()->RunUntilIdle(); |
3580 | 3566 |
3581 // Write and read from the cache (20-59). | 3567 // Write and read from the cache (20-59). |
3582 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; | 3568 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; |
3583 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; | 3569 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; |
3584 net::CapturingBoundNetLog log; | 3570 net::CapturingBoundNetLog log; |
3585 net::LoadTimingInfo load_timing_info; | 3571 net::LoadTimingInfo load_timing_info; |
3586 RunTransactionTestWithResponseAndGetTiming( | 3572 RunTransactionTestWithResponseAndGetTiming(cache.http_cache(), |
3587 cache.http_cache(), transaction, &headers, log.bound(), | 3573 transaction, |
3588 &load_timing_info); | 3574 &headers, |
| 3575 log.bound(), |
| 3576 &load_timing_info); |
3589 | 3577 |
3590 Verify206Response(headers, 20, 59); | 3578 Verify206Response(headers, 20, 59); |
3591 EXPECT_EQ(4, cache.network_layer()->transaction_count()); | 3579 EXPECT_EQ(4, cache.network_layer()->transaction_count()); |
3592 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 3580 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
3593 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3581 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3594 TestLoadTimingNetworkRequest(load_timing_info); | 3582 TestLoadTimingNetworkRequest(load_timing_info); |
3595 | 3583 |
3596 RemoveMockTransaction(&transaction); | 3584 RemoveMockTransaction(&transaction); |
3597 } | 3585 } |
3598 | 3586 |
(...skipping 14 matching lines...) Expand all Loading... |
3613 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 3601 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
3614 | 3602 |
3615 Verify206Response(headers, 40, 49); | 3603 Verify206Response(headers, 40, 49); |
3616 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3604 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3617 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3605 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3618 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3606 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3619 | 3607 |
3620 // Read from the cache (40-49). | 3608 // Read from the cache (40-49). |
3621 net::CapturingBoundNetLog log; | 3609 net::CapturingBoundNetLog log; |
3622 net::LoadTimingInfo load_timing_info; | 3610 net::LoadTimingInfo load_timing_info; |
3623 RunTransactionTestWithResponseAndGetTiming( | 3611 RunTransactionTestWithResponseAndGetTiming(cache.http_cache(), |
3624 cache.http_cache(), transaction, &headers, log.bound(), | 3612 transaction, |
3625 &load_timing_info); | 3613 &headers, |
| 3614 log.bound(), |
| 3615 &load_timing_info); |
3626 | 3616 |
3627 Verify206Response(headers, 40, 49); | 3617 Verify206Response(headers, 40, 49); |
3628 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3618 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3629 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3619 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
3630 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3620 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3631 TestLoadTimingCachedResponse(load_timing_info); | 3621 TestLoadTimingCachedResponse(load_timing_info); |
3632 | 3622 |
3633 // Read again forcing the revalidation. | 3623 // Read again forcing the revalidation. |
3634 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; | 3624 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; |
3635 RunTransactionTestWithResponseAndGetTiming( | 3625 RunTransactionTestWithResponseAndGetTiming(cache.http_cache(), |
3636 cache.http_cache(), transaction, &headers, log.bound(), | 3626 transaction, |
3637 &load_timing_info); | 3627 &headers, |
| 3628 log.bound(), |
| 3629 &load_timing_info); |
3638 | 3630 |
3639 Verify206Response(headers, 40, 49); | 3631 Verify206Response(headers, 40, 49); |
3640 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3632 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3641 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3633 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
3642 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3634 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3643 TestLoadTimingNetworkRequest(load_timing_info); | 3635 TestLoadTimingNetworkRequest(load_timing_info); |
3644 | 3636 |
3645 RemoveMockTransaction(&transaction); | 3637 RemoveMockTransaction(&transaction); |
3646 } | 3638 } |
3647 | 3639 |
(...skipping 29 matching lines...) Expand all Loading... |
3677 RemoveMockTransaction(&transaction); | 3669 RemoveMockTransaction(&transaction); |
3678 } | 3670 } |
3679 | 3671 |
3680 // Tests that we deal with 304s for range requests. | 3672 // Tests that we deal with 304s for range requests. |
3681 TEST(HttpCache, RangeGET_304) { | 3673 TEST(HttpCache, RangeGET_304) { |
3682 MockHttpCache cache; | 3674 MockHttpCache cache; |
3683 AddMockTransaction(&kRangeGET_TransactionOK); | 3675 AddMockTransaction(&kRangeGET_TransactionOK); |
3684 std::string headers; | 3676 std::string headers; |
3685 | 3677 |
3686 // Write to the cache (40-49). | 3678 // Write to the cache (40-49). |
3687 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 3679 RunTransactionTestWithResponse( |
3688 &headers); | 3680 cache.http_cache(), kRangeGET_TransactionOK, &headers); |
3689 | 3681 |
3690 Verify206Response(headers, 40, 49); | 3682 Verify206Response(headers, 40, 49); |
3691 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3683 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3692 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3684 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3693 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3685 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3694 | 3686 |
3695 // Read from the cache (40-49). | 3687 // Read from the cache (40-49). |
3696 RangeTransactionServer handler; | 3688 RangeTransactionServer handler; |
3697 handler.set_not_modified(true); | 3689 handler.set_not_modified(true); |
3698 MockTransaction transaction(kRangeGET_TransactionOK); | 3690 MockTransaction transaction(kRangeGET_TransactionOK); |
3699 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; | 3691 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; |
3700 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 3692 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
3701 | 3693 |
3702 Verify206Response(headers, 40, 49); | 3694 Verify206Response(headers, 40, 49); |
3703 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3695 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3704 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3696 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
3705 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3697 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3706 | 3698 |
3707 RemoveMockTransaction(&kRangeGET_TransactionOK); | 3699 RemoveMockTransaction(&kRangeGET_TransactionOK); |
3708 } | 3700 } |
3709 | 3701 |
3710 // Tests that we deal with 206s when revalidating range requests. | 3702 // Tests that we deal with 206s when revalidating range requests. |
3711 TEST(HttpCache, RangeGET_ModifiedResult) { | 3703 TEST(HttpCache, RangeGET_ModifiedResult) { |
3712 MockHttpCache cache; | 3704 MockHttpCache cache; |
3713 AddMockTransaction(&kRangeGET_TransactionOK); | 3705 AddMockTransaction(&kRangeGET_TransactionOK); |
3714 std::string headers; | 3706 std::string headers; |
3715 | 3707 |
3716 // Write to the cache (40-49). | 3708 // Write to the cache (40-49). |
3717 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 3709 RunTransactionTestWithResponse( |
3718 &headers); | 3710 cache.http_cache(), kRangeGET_TransactionOK, &headers); |
3719 | 3711 |
3720 Verify206Response(headers, 40, 49); | 3712 Verify206Response(headers, 40, 49); |
3721 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3713 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3722 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3714 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3723 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3715 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3724 | 3716 |
3725 // Attempt to read from the cache (40-49). | 3717 // Attempt to read from the cache (40-49). |
3726 RangeTransactionServer handler; | 3718 RangeTransactionServer handler; |
3727 handler.set_modified(true); | 3719 handler.set_modified(true); |
3728 MockTransaction transaction(kRangeGET_TransactionOK); | 3720 MockTransaction transaction(kRangeGET_TransactionOK); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3872 | 3864 |
3873 // Tests that we can handle non-range requests when we have cached a range. | 3865 // Tests that we can handle non-range requests when we have cached a range. |
3874 TEST(HttpCache, GET_Previous206) { | 3866 TEST(HttpCache, GET_Previous206) { |
3875 MockHttpCache cache; | 3867 MockHttpCache cache; |
3876 AddMockTransaction(&kRangeGET_TransactionOK); | 3868 AddMockTransaction(&kRangeGET_TransactionOK); |
3877 std::string headers; | 3869 std::string headers; |
3878 net::CapturingBoundNetLog log; | 3870 net::CapturingBoundNetLog log; |
3879 net::LoadTimingInfo load_timing_info; | 3871 net::LoadTimingInfo load_timing_info; |
3880 | 3872 |
3881 // Write to the cache (40-49). | 3873 // Write to the cache (40-49). |
3882 RunTransactionTestWithResponseAndGetTiming( | 3874 RunTransactionTestWithResponseAndGetTiming(cache.http_cache(), |
3883 cache.http_cache(), kRangeGET_TransactionOK, &headers, log.bound(), | 3875 kRangeGET_TransactionOK, |
3884 &load_timing_info); | 3876 &headers, |
| 3877 log.bound(), |
| 3878 &load_timing_info); |
3885 | 3879 |
3886 Verify206Response(headers, 40, 49); | 3880 Verify206Response(headers, 40, 49); |
3887 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3881 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3888 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3882 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3889 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3883 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3890 TestLoadTimingNetworkRequest(load_timing_info); | 3884 TestLoadTimingNetworkRequest(load_timing_info); |
3891 | 3885 |
3892 // Write and read from the cache (0-79), when not asked for a range. | 3886 // Write and read from the cache (0-79), when not asked for a range. |
3893 MockTransaction transaction(kRangeGET_TransactionOK); | 3887 MockTransaction transaction(kRangeGET_TransactionOK); |
3894 transaction.request_headers = EXTRA_HEADER; | 3888 transaction.request_headers = EXTRA_HEADER; |
3895 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 3889 transaction.data = |
3896 "rg: 50-59 rg: 60-69 rg: 70-79 "; | 3890 "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " |
3897 RunTransactionTestWithResponseAndGetTiming( | 3891 "rg: 50-59 rg: 60-69 rg: 70-79 "; |
3898 cache.http_cache(), transaction, &headers, log.bound(), | 3892 RunTransactionTestWithResponseAndGetTiming(cache.http_cache(), |
3899 &load_timing_info); | 3893 transaction, |
| 3894 &headers, |
| 3895 log.bound(), |
| 3896 &load_timing_info); |
3900 | 3897 |
3901 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); | 3898 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); |
3902 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 3899 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
3903 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3900 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
3904 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3901 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3905 TestLoadTimingNetworkRequest(load_timing_info); | 3902 TestLoadTimingNetworkRequest(load_timing_info); |
3906 | 3903 |
3907 RemoveMockTransaction(&kRangeGET_TransactionOK); | 3904 RemoveMockTransaction(&kRangeGET_TransactionOK); |
3908 } | 3905 } |
3909 | 3906 |
3910 // Tests that we can handle non-range requests when we have cached the first | 3907 // Tests that we can handle non-range requests when we have cached the first |
3911 // part of the object and the server replies with 304 (Not Modified). | 3908 // part of the object and the server replies with 304 (Not Modified). |
3912 TEST(HttpCache, GET_Previous206_NotModified) { | 3909 TEST(HttpCache, GET_Previous206_NotModified) { |
3913 MockHttpCache cache; | 3910 MockHttpCache cache; |
3914 | 3911 |
3915 MockTransaction transaction(kRangeGET_TransactionOK); | 3912 MockTransaction transaction(kRangeGET_TransactionOK); |
3916 AddMockTransaction(&transaction); | 3913 AddMockTransaction(&transaction); |
3917 std::string headers; | 3914 std::string headers; |
3918 net::CapturingBoundNetLog log; | 3915 net::CapturingBoundNetLog log; |
3919 net::LoadTimingInfo load_timing_info; | 3916 net::LoadTimingInfo load_timing_info; |
3920 | 3917 |
3921 // Write to the cache (0-9). | 3918 // Write to the cache (0-9). |
3922 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; | 3919 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; |
3923 transaction.data = "rg: 00-09 "; | 3920 transaction.data = "rg: 00-09 "; |
3924 RunTransactionTestWithResponseAndGetTiming( | 3921 RunTransactionTestWithResponseAndGetTiming(cache.http_cache(), |
3925 cache.http_cache(), transaction, &headers, log.bound(), | 3922 transaction, |
3926 &load_timing_info); | 3923 &headers, |
| 3924 log.bound(), |
| 3925 &load_timing_info); |
3927 Verify206Response(headers, 0, 9); | 3926 Verify206Response(headers, 0, 9); |
3928 TestLoadTimingNetworkRequest(load_timing_info); | 3927 TestLoadTimingNetworkRequest(load_timing_info); |
3929 | 3928 |
3930 // Write to the cache (70-79). | 3929 // Write to the cache (70-79). |
3931 transaction.request_headers = "Range: bytes = 70-79\r\n" EXTRA_HEADER; | 3930 transaction.request_headers = "Range: bytes = 70-79\r\n" EXTRA_HEADER; |
3932 transaction.data = "rg: 70-79 "; | 3931 transaction.data = "rg: 70-79 "; |
3933 RunTransactionTestWithResponseAndGetTiming( | 3932 RunTransactionTestWithResponseAndGetTiming(cache.http_cache(), |
3934 cache.http_cache(), transaction, &headers, log.bound(), | 3933 transaction, |
3935 &load_timing_info); | 3934 &headers, |
| 3935 log.bound(), |
| 3936 &load_timing_info); |
3936 Verify206Response(headers, 70, 79); | 3937 Verify206Response(headers, 70, 79); |
3937 | 3938 |
3938 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3939 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3939 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3940 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
3940 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3941 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3941 TestLoadTimingNetworkRequest(load_timing_info); | 3942 TestLoadTimingNetworkRequest(load_timing_info); |
3942 | 3943 |
3943 // Read from the cache (0-9), write and read from cache (10 - 79). | 3944 // Read from the cache (0-9), write and read from cache (10 - 79). |
3944 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; | 3945 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; |
3945 transaction.request_headers = "Foo: bar\r\n" EXTRA_HEADER; | 3946 transaction.request_headers = "Foo: bar\r\n" EXTRA_HEADER; |
3946 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 3947 transaction.data = |
3947 "rg: 50-59 rg: 60-69 rg: 70-79 "; | 3948 "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " |
3948 RunTransactionTestWithResponseAndGetTiming( | 3949 "rg: 50-59 rg: 60-69 rg: 70-79 "; |
3949 cache.http_cache(), transaction, &headers, log.bound(), | 3950 RunTransactionTestWithResponseAndGetTiming(cache.http_cache(), |
3950 &load_timing_info); | 3951 transaction, |
| 3952 &headers, |
| 3953 log.bound(), |
| 3954 &load_timing_info); |
3951 | 3955 |
3952 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); | 3956 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); |
3953 EXPECT_EQ(4, cache.network_layer()->transaction_count()); | 3957 EXPECT_EQ(4, cache.network_layer()->transaction_count()); |
3954 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 3958 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
3955 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3959 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3956 TestLoadTimingNetworkRequest(load_timing_info); | 3960 TestLoadTimingNetworkRequest(load_timing_info); |
3957 | 3961 |
3958 RemoveMockTransaction(&transaction); | 3962 RemoveMockTransaction(&transaction); |
3959 } | 3963 } |
3960 | 3964 |
(...skipping 20 matching lines...) Expand all Loading... |
3981 // server will not modify the response so we'll get the default range... a | 3985 // server will not modify the response so we'll get the default range... a |
3982 // real server will answer with 200. | 3986 // real server will answer with 200. |
3983 MockTransaction transaction2(kRangeGET_TransactionOK); | 3987 MockTransaction transaction2(kRangeGET_TransactionOK); |
3984 transaction2.request_headers = EXTRA_HEADER; | 3988 transaction2.request_headers = EXTRA_HEADER; |
3985 transaction2.load_flags |= net::LOAD_VALIDATE_CACHE; | 3989 transaction2.load_flags |= net::LOAD_VALIDATE_CACHE; |
3986 transaction2.data = "Not a range"; | 3990 transaction2.data = "Not a range"; |
3987 RangeTransactionServer handler; | 3991 RangeTransactionServer handler; |
3988 handler.set_modified(true); | 3992 handler.set_modified(true); |
3989 net::CapturingBoundNetLog log; | 3993 net::CapturingBoundNetLog log; |
3990 net::LoadTimingInfo load_timing_info; | 3994 net::LoadTimingInfo load_timing_info; |
3991 RunTransactionTestWithResponseAndGetTiming( | 3995 RunTransactionTestWithResponseAndGetTiming(cache.http_cache(), |
3992 cache.http_cache(), transaction2, &headers, log.bound(), | 3996 transaction2, |
3993 &load_timing_info); | 3997 &headers, |
| 3998 log.bound(), |
| 3999 &load_timing_info); |
3994 | 4000 |
3995 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); | 4001 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); |
3996 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 4002 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
3997 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4003 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
3998 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4004 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
3999 TestLoadTimingNetworkRequest(load_timing_info); | 4005 TestLoadTimingNetworkRequest(load_timing_info); |
4000 | 4006 |
4001 // Verify that the previous request deleted the entry. | 4007 // Verify that the previous request deleted the entry. |
4002 RunTransactionTest(cache.http_cache(), transaction); | 4008 RunTransactionTest(cache.http_cache(), transaction); |
4003 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 4009 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
4004 | 4010 |
4005 RemoveMockTransaction(&transaction); | 4011 RemoveMockTransaction(&transaction); |
4006 } | 4012 } |
4007 | 4013 |
4008 // Tests that we can handle cached 206 responses that are not sparse. | 4014 // Tests that we can handle cached 206 responses that are not sparse. |
4009 TEST(HttpCache, GET_Previous206_NotSparse) { | 4015 TEST(HttpCache, GET_Previous206_NotSparse) { |
4010 MockHttpCache cache; | 4016 MockHttpCache cache; |
4011 | 4017 |
4012 // Create a disk cache entry that stores 206 headers while not being sparse. | 4018 // Create a disk cache entry that stores 206 headers while not being sparse. |
4013 disk_cache::Entry* entry; | 4019 disk_cache::Entry* entry; |
4014 ASSERT_TRUE(cache.CreateBackendEntry(kSimpleGET_Transaction.url, &entry, | 4020 ASSERT_TRUE( |
4015 NULL)); | 4021 cache.CreateBackendEntry(kSimpleGET_Transaction.url, &entry, NULL)); |
4016 | 4022 |
4017 std::string raw_headers(kRangeGET_TransactionOK.status); | 4023 std::string raw_headers(kRangeGET_TransactionOK.status); |
4018 raw_headers.append("\n"); | 4024 raw_headers.append("\n"); |
4019 raw_headers.append(kRangeGET_TransactionOK.response_headers); | 4025 raw_headers.append(kRangeGET_TransactionOK.response_headers); |
4020 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), | 4026 raw_headers = |
4021 raw_headers.size()); | 4027 net::HttpUtil::AssembleRawHeaders(raw_headers.data(), raw_headers.size()); |
4022 | 4028 |
4023 net::HttpResponseInfo response; | 4029 net::HttpResponseInfo response; |
4024 response.headers = new net::HttpResponseHeaders(raw_headers); | 4030 response.headers = new net::HttpResponseHeaders(raw_headers); |
4025 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); | 4031 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); |
4026 | 4032 |
4027 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500)); | 4033 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500)); |
4028 int len = static_cast<int>(base::strlcpy(buf->data(), | 4034 int len = static_cast<int>( |
4029 kRangeGET_TransactionOK.data, 500)); | 4035 base::strlcpy(buf->data(), kRangeGET_TransactionOK.data, 500)); |
4030 net::TestCompletionCallback cb; | 4036 net::TestCompletionCallback cb; |
4031 int rv = entry->WriteData(1, 0, buf.get(), len, cb.callback(), true); | 4037 int rv = entry->WriteData(1, 0, buf.get(), len, cb.callback(), true); |
4032 EXPECT_EQ(len, cb.GetResult(rv)); | 4038 EXPECT_EQ(len, cb.GetResult(rv)); |
4033 entry->Close(); | 4039 entry->Close(); |
4034 | 4040 |
4035 // Now see that we don't use the stored entry. | 4041 // Now see that we don't use the stored entry. |
4036 std::string headers; | 4042 std::string headers; |
4037 net::CapturingBoundNetLog log; | 4043 net::CapturingBoundNetLog log; |
4038 net::LoadTimingInfo load_timing_info; | 4044 net::LoadTimingInfo load_timing_info; |
4039 RunTransactionTestWithResponseAndGetTiming( | 4045 RunTransactionTestWithResponseAndGetTiming(cache.http_cache(), |
4040 cache.http_cache(), kSimpleGET_Transaction, &headers, log.bound(), | 4046 kSimpleGET_Transaction, |
4041 &load_timing_info); | 4047 &headers, |
| 4048 log.bound(), |
| 4049 &load_timing_info); |
4042 | 4050 |
4043 // We are expecting a 200. | 4051 // We are expecting a 200. |
4044 std::string expected_headers(kSimpleGET_Transaction.status); | 4052 std::string expected_headers(kSimpleGET_Transaction.status); |
4045 expected_headers.append("\n"); | 4053 expected_headers.append("\n"); |
4046 expected_headers.append(kSimpleGET_Transaction.response_headers); | 4054 expected_headers.append(kSimpleGET_Transaction.response_headers); |
4047 EXPECT_EQ(expected_headers, headers); | 4055 EXPECT_EQ(expected_headers, headers); |
4048 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4056 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
4049 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4057 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
4050 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 4058 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
4051 TestLoadTimingNetworkRequest(load_timing_info); | 4059 TestLoadTimingNetworkRequest(load_timing_info); |
4052 } | 4060 } |
4053 | 4061 |
4054 // Tests that we can handle cached 206 responses that are not sparse. This time | 4062 // Tests that we can handle cached 206 responses that are not sparse. This time |
4055 // we issue a range request and expect to receive a range. | 4063 // we issue a range request and expect to receive a range. |
4056 TEST(HttpCache, RangeGET_Previous206_NotSparse_2) { | 4064 TEST(HttpCache, RangeGET_Previous206_NotSparse_2) { |
4057 MockHttpCache cache; | 4065 MockHttpCache cache; |
4058 AddMockTransaction(&kRangeGET_TransactionOK); | 4066 AddMockTransaction(&kRangeGET_TransactionOK); |
4059 | 4067 |
4060 // Create a disk cache entry that stores 206 headers while not being sparse. | 4068 // Create a disk cache entry that stores 206 headers while not being sparse. |
4061 disk_cache::Entry* entry; | 4069 disk_cache::Entry* entry; |
4062 ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry, | 4070 ASSERT_TRUE( |
4063 NULL)); | 4071 cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry, NULL)); |
4064 | 4072 |
4065 std::string raw_headers(kRangeGET_TransactionOK.status); | 4073 std::string raw_headers(kRangeGET_TransactionOK.status); |
4066 raw_headers.append("\n"); | 4074 raw_headers.append("\n"); |
4067 raw_headers.append(kRangeGET_TransactionOK.response_headers); | 4075 raw_headers.append(kRangeGET_TransactionOK.response_headers); |
4068 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), | 4076 raw_headers = |
4069 raw_headers.size()); | 4077 net::HttpUtil::AssembleRawHeaders(raw_headers.data(), raw_headers.size()); |
4070 | 4078 |
4071 net::HttpResponseInfo response; | 4079 net::HttpResponseInfo response; |
4072 response.headers = new net::HttpResponseHeaders(raw_headers); | 4080 response.headers = new net::HttpResponseHeaders(raw_headers); |
4073 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); | 4081 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); |
4074 | 4082 |
4075 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500)); | 4083 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500)); |
4076 int len = static_cast<int>(base::strlcpy(buf->data(), | 4084 int len = static_cast<int>( |
4077 kRangeGET_TransactionOK.data, 500)); | 4085 base::strlcpy(buf->data(), kRangeGET_TransactionOK.data, 500)); |
4078 net::TestCompletionCallback cb; | 4086 net::TestCompletionCallback cb; |
4079 int rv = entry->WriteData(1, 0, buf.get(), len, cb.callback(), true); | 4087 int rv = entry->WriteData(1, 0, buf.get(), len, cb.callback(), true); |
4080 EXPECT_EQ(len, cb.GetResult(rv)); | 4088 EXPECT_EQ(len, cb.GetResult(rv)); |
4081 entry->Close(); | 4089 entry->Close(); |
4082 | 4090 |
4083 // Now see that we don't use the stored entry. | 4091 // Now see that we don't use the stored entry. |
4084 std::string headers; | 4092 std::string headers; |
4085 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 4093 RunTransactionTestWithResponse( |
4086 &headers); | 4094 cache.http_cache(), kRangeGET_TransactionOK, &headers); |
4087 | 4095 |
4088 // We are expecting a 206. | 4096 // We are expecting a 206. |
4089 Verify206Response(headers, 40, 49); | 4097 Verify206Response(headers, 40, 49); |
4090 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4098 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
4091 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4099 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
4092 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 4100 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
4093 | 4101 |
4094 RemoveMockTransaction(&kRangeGET_TransactionOK); | 4102 RemoveMockTransaction(&kRangeGET_TransactionOK); |
4095 } | 4103 } |
4096 | 4104 |
4097 // Tests that we can handle cached 206 responses that can't be validated. | 4105 // Tests that we can handle cached 206 responses that can't be validated. |
4098 TEST(HttpCache, GET_Previous206_NotValidation) { | 4106 TEST(HttpCache, GET_Previous206_NotValidation) { |
4099 MockHttpCache cache; | 4107 MockHttpCache cache; |
4100 | 4108 |
4101 // Create a disk cache entry that stores 206 headers. | 4109 // Create a disk cache entry that stores 206 headers. |
4102 disk_cache::Entry* entry; | 4110 disk_cache::Entry* entry; |
4103 ASSERT_TRUE(cache.CreateBackendEntry(kSimpleGET_Transaction.url, &entry, | 4111 ASSERT_TRUE( |
4104 NULL)); | 4112 cache.CreateBackendEntry(kSimpleGET_Transaction.url, &entry, NULL)); |
4105 | 4113 |
4106 // Make sure that the headers cannot be validated with the server. | 4114 // Make sure that the headers cannot be validated with the server. |
4107 std::string raw_headers(kRangeGET_TransactionOK.status); | 4115 std::string raw_headers(kRangeGET_TransactionOK.status); |
4108 raw_headers.append("\n"); | 4116 raw_headers.append("\n"); |
4109 raw_headers.append("Content-Length: 80\n"); | 4117 raw_headers.append("Content-Length: 80\n"); |
4110 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), | 4118 raw_headers = |
4111 raw_headers.size()); | 4119 net::HttpUtil::AssembleRawHeaders(raw_headers.data(), raw_headers.size()); |
4112 | 4120 |
4113 net::HttpResponseInfo response; | 4121 net::HttpResponseInfo response; |
4114 response.headers = new net::HttpResponseHeaders(raw_headers); | 4122 response.headers = new net::HttpResponseHeaders(raw_headers); |
4115 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); | 4123 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, false)); |
4116 | 4124 |
4117 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500)); | 4125 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500)); |
4118 int len = static_cast<int>(base::strlcpy(buf->data(), | 4126 int len = static_cast<int>( |
4119 kRangeGET_TransactionOK.data, 500)); | 4127 base::strlcpy(buf->data(), kRangeGET_TransactionOK.data, 500)); |
4120 net::TestCompletionCallback cb; | 4128 net::TestCompletionCallback cb; |
4121 int rv = entry->WriteData(1, 0, buf.get(), len, cb.callback(), true); | 4129 int rv = entry->WriteData(1, 0, buf.get(), len, cb.callback(), true); |
4122 EXPECT_EQ(len, cb.GetResult(rv)); | 4130 EXPECT_EQ(len, cb.GetResult(rv)); |
4123 entry->Close(); | 4131 entry->Close(); |
4124 | 4132 |
4125 // Now see that we don't use the stored entry. | 4133 // Now see that we don't use the stored entry. |
4126 std::string headers; | 4134 std::string headers; |
4127 RunTransactionTestWithResponse(cache.http_cache(), kSimpleGET_Transaction, | 4135 RunTransactionTestWithResponse( |
4128 &headers); | 4136 cache.http_cache(), kSimpleGET_Transaction, &headers); |
4129 | 4137 |
4130 // We are expecting a 200. | 4138 // We are expecting a 200. |
4131 std::string expected_headers(kSimpleGET_Transaction.status); | 4139 std::string expected_headers(kSimpleGET_Transaction.status); |
4132 expected_headers.append("\n"); | 4140 expected_headers.append("\n"); |
4133 expected_headers.append(kSimpleGET_Transaction.response_headers); | 4141 expected_headers.append(kSimpleGET_Transaction.response_headers); |
4134 EXPECT_EQ(expected_headers, headers); | 4142 EXPECT_EQ(expected_headers, headers); |
4135 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4143 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
4136 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4144 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
4137 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 4145 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
4138 } | 4146 } |
4139 | 4147 |
4140 // Tests that we can handle range requests with cached 200 responses. | 4148 // Tests that we can handle range requests with cached 200 responses. |
4141 TEST(HttpCache, RangeGET_Previous200) { | 4149 TEST(HttpCache, RangeGET_Previous200) { |
4142 MockHttpCache cache; | 4150 MockHttpCache cache; |
4143 | 4151 |
4144 // Store the whole thing with status 200. | 4152 // Store the whole thing with status 200. |
4145 MockTransaction transaction(kTypicalGET_Transaction); | 4153 MockTransaction transaction(kTypicalGET_Transaction); |
4146 transaction.url = kRangeGET_TransactionOK.url; | 4154 transaction.url = kRangeGET_TransactionOK.url; |
4147 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 4155 transaction.data = |
4148 "rg: 50-59 rg: 60-69 rg: 70-79 "; | 4156 "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " |
| 4157 "rg: 50-59 rg: 60-69 rg: 70-79 "; |
4149 AddMockTransaction(&transaction); | 4158 AddMockTransaction(&transaction); |
4150 RunTransactionTest(cache.http_cache(), transaction); | 4159 RunTransactionTest(cache.http_cache(), transaction); |
4151 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4160 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
4152 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 4161 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
4153 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4162 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4154 | 4163 |
4155 RemoveMockTransaction(&transaction); | 4164 RemoveMockTransaction(&transaction); |
4156 AddMockTransaction(&kRangeGET_TransactionOK); | 4165 AddMockTransaction(&kRangeGET_TransactionOK); |
4157 | 4166 |
4158 // Now see that we use the stored entry. | 4167 // Now see that we use the stored entry. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4247 } | 4256 } |
4248 | 4257 |
4249 // Tests that a range request that falls outside of the size that we know about | 4258 // Tests that a range request that falls outside of the size that we know about |
4250 // only deletes the entry if the resource has indeed changed. | 4259 // only deletes the entry if the resource has indeed changed. |
4251 TEST(HttpCache, RangeGET_MoreThanCurrentSize) { | 4260 TEST(HttpCache, RangeGET_MoreThanCurrentSize) { |
4252 MockHttpCache cache; | 4261 MockHttpCache cache; |
4253 AddMockTransaction(&kRangeGET_TransactionOK); | 4262 AddMockTransaction(&kRangeGET_TransactionOK); |
4254 std::string headers; | 4263 std::string headers; |
4255 | 4264 |
4256 // Write to the cache (40-49). | 4265 // Write to the cache (40-49). |
4257 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 4266 RunTransactionTestWithResponse( |
4258 &headers); | 4267 cache.http_cache(), kRangeGET_TransactionOK, &headers); |
4259 | 4268 |
4260 Verify206Response(headers, 40, 49); | 4269 Verify206Response(headers, 40, 49); |
4261 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4270 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
4262 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 4271 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
4263 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4272 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4264 | 4273 |
4265 // A weird request should not delete this entry. Ask for bytes 120-. | 4274 // A weird request should not delete this entry. Ask for bytes 120-. |
4266 MockTransaction transaction(kRangeGET_TransactionOK); | 4275 MockTransaction transaction(kRangeGET_TransactionOK); |
4267 transaction.request_headers = "Range: bytes = 120-\r\n" EXTRA_HEADER; | 4276 transaction.request_headers = "Range: bytes = 120-\r\n" EXTRA_HEADER; |
4268 transaction.data = ""; | 4277 transaction.data = ""; |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4421 RemoveMockTransaction(&kRangeGET_TransactionOK); | 4430 RemoveMockTransaction(&kRangeGET_TransactionOK); |
4422 } | 4431 } |
4423 | 4432 |
4424 // Tests that an invalid range response results in no cached entry. | 4433 // Tests that an invalid range response results in no cached entry. |
4425 TEST(HttpCache, RangeGET_InvalidResponse1) { | 4434 TEST(HttpCache, RangeGET_InvalidResponse1) { |
4426 MockHttpCache cache; | 4435 MockHttpCache cache; |
4427 std::string headers; | 4436 std::string headers; |
4428 | 4437 |
4429 MockTransaction transaction(kRangeGET_TransactionOK); | 4438 MockTransaction transaction(kRangeGET_TransactionOK); |
4430 transaction.handler = NULL; | 4439 transaction.handler = NULL; |
4431 transaction.response_headers = "Content-Range: bytes 40-49/45\n" | 4440 transaction.response_headers = |
4432 "Content-Length: 10\n"; | 4441 "Content-Range: bytes 40-49/45\n" |
| 4442 "Content-Length: 10\n"; |
4433 AddMockTransaction(&transaction); | 4443 AddMockTransaction(&transaction); |
4434 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 4444 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
4435 | 4445 |
4436 std::string expected(transaction.status); | 4446 std::string expected(transaction.status); |
4437 expected.append("\n"); | 4447 expected.append("\n"); |
4438 expected.append(transaction.response_headers); | 4448 expected.append(transaction.response_headers); |
4439 EXPECT_EQ(expected, headers); | 4449 EXPECT_EQ(expected, headers); |
4440 | 4450 |
4441 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4451 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
4442 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 4452 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
4443 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4453 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4444 | 4454 |
4445 // Verify that we don't have a cached entry. | 4455 // Verify that we don't have a cached entry. |
4446 disk_cache::Entry* entry; | 4456 disk_cache::Entry* entry; |
4447 EXPECT_FALSE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry)); | 4457 EXPECT_FALSE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry)); |
4448 | 4458 |
4449 RemoveMockTransaction(&kRangeGET_TransactionOK); | 4459 RemoveMockTransaction(&kRangeGET_TransactionOK); |
4450 } | 4460 } |
4451 | 4461 |
4452 // Tests that we reject a range that doesn't match the content-length. | 4462 // Tests that we reject a range that doesn't match the content-length. |
4453 TEST(HttpCache, RangeGET_InvalidResponse2) { | 4463 TEST(HttpCache, RangeGET_InvalidResponse2) { |
4454 MockHttpCache cache; | 4464 MockHttpCache cache; |
4455 std::string headers; | 4465 std::string headers; |
4456 | 4466 |
4457 MockTransaction transaction(kRangeGET_TransactionOK); | 4467 MockTransaction transaction(kRangeGET_TransactionOK); |
4458 transaction.handler = NULL; | 4468 transaction.handler = NULL; |
4459 transaction.response_headers = "Content-Range: bytes 40-49/80\n" | 4469 transaction.response_headers = |
4460 "Content-Length: 20\n"; | 4470 "Content-Range: bytes 40-49/80\n" |
| 4471 "Content-Length: 20\n"; |
4461 AddMockTransaction(&transaction); | 4472 AddMockTransaction(&transaction); |
4462 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 4473 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
4463 | 4474 |
4464 std::string expected(transaction.status); | 4475 std::string expected(transaction.status); |
4465 expected.append("\n"); | 4476 expected.append("\n"); |
4466 expected.append(transaction.response_headers); | 4477 expected.append(transaction.response_headers); |
4467 EXPECT_EQ(expected, headers); | 4478 EXPECT_EQ(expected, headers); |
4468 | 4479 |
4469 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4480 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
4470 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 4481 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
(...skipping 24 matching lines...) Expand all Loading... |
4495 Verify206Response(headers, 50, 59); | 4506 Verify206Response(headers, 50, 59); |
4496 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4507 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
4497 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 4508 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
4498 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4509 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4499 | 4510 |
4500 RemoveMockTransaction(&transaction); | 4511 RemoveMockTransaction(&transaction); |
4501 AddMockTransaction(&kRangeGET_TransactionOK); | 4512 AddMockTransaction(&kRangeGET_TransactionOK); |
4502 | 4513 |
4503 // This transaction will report a resource size of 80 bytes, and we think it's | 4514 // This transaction will report a resource size of 80 bytes, and we think it's |
4504 // 160 so we should ignore the response. | 4515 // 160 so we should ignore the response. |
4505 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 4516 RunTransactionTestWithResponse( |
4506 &headers); | 4517 cache.http_cache(), kRangeGET_TransactionOK, &headers); |
4507 | 4518 |
4508 Verify206Response(headers, 40, 49); | 4519 Verify206Response(headers, 40, 49); |
4509 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 4520 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
4510 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4521 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
4511 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4522 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4512 | 4523 |
4513 // Verify that we cached the first response but not the second one. | 4524 // Verify that we cached the first response but not the second one. |
4514 disk_cache::Entry* en; | 4525 disk_cache::Entry* en; |
4515 ASSERT_TRUE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &en)); | 4526 ASSERT_TRUE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &en)); |
4516 | 4527 |
4517 int64 cached_start = 0; | 4528 int64 cached_start = 0; |
4518 net::TestCompletionCallback cb; | 4529 net::TestCompletionCallback cb; |
4519 int rv = en->GetAvailableRange(40, 20, &cached_start, cb.callback()); | 4530 int rv = en->GetAvailableRange(40, 20, &cached_start, cb.callback()); |
4520 EXPECT_EQ(10, cb.GetResult(rv)); | 4531 EXPECT_EQ(10, cb.GetResult(rv)); |
4521 EXPECT_EQ(50, cached_start); | 4532 EXPECT_EQ(50, cached_start); |
4522 en->Close(); | 4533 en->Close(); |
4523 | 4534 |
4524 RemoveMockTransaction(&kRangeGET_TransactionOK); | 4535 RemoveMockTransaction(&kRangeGET_TransactionOK); |
4525 } | 4536 } |
4526 | 4537 |
4527 // Tests that we handle large range values properly. | 4538 // Tests that we handle large range values properly. |
4528 TEST(HttpCache, RangeGET_LargeValues) { | 4539 TEST(HttpCache, RangeGET_LargeValues) { |
4529 // We need a real sparse cache for this test. | 4540 // We need a real sparse cache for this test. |
4530 MockHttpCache cache(net::HttpCache::DefaultBackend::InMemory(1024 * 1024)); | 4541 MockHttpCache cache(net::HttpCache::DefaultBackend::InMemory(1024 * 1024)); |
4531 std::string headers; | 4542 std::string headers; |
4532 | 4543 |
4533 MockTransaction transaction(kRangeGET_TransactionOK); | 4544 MockTransaction transaction(kRangeGET_TransactionOK); |
4534 transaction.handler = NULL; | 4545 transaction.handler = NULL; |
4535 transaction.request_headers = "Range: bytes = 4294967288-4294967297\r\n" | 4546 transaction.request_headers = |
4536 EXTRA_HEADER; | 4547 "Range: bytes = 4294967288-4294967297\r\n" EXTRA_HEADER; |
4537 transaction.response_headers = | 4548 transaction.response_headers = |
4538 "ETag: \"foo\"\n" | 4549 "ETag: \"foo\"\n" |
4539 "Content-Range: bytes 4294967288-4294967297/4294967299\n" | 4550 "Content-Range: bytes 4294967288-4294967297/4294967299\n" |
4540 "Content-Length: 10\n"; | 4551 "Content-Length: 10\n"; |
4541 AddMockTransaction(&transaction); | 4552 AddMockTransaction(&transaction); |
4542 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 4553 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
4543 | 4554 |
4544 std::string expected(transaction.status); | 4555 std::string expected(transaction.status); |
4545 expected.append("\n"); | 4556 expected.append("\n"); |
4546 expected.append(transaction.response_headers); | 4557 expected.append(transaction.response_headers); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4696 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4707 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4697 | 4708 |
4698 RemoveMockTransaction(&kRangeGET_TransactionOK); | 4709 RemoveMockTransaction(&kRangeGET_TransactionOK); |
4699 } | 4710 } |
4700 #endif | 4711 #endif |
4701 | 4712 |
4702 // Tests the handling of the "truncation" flag. | 4713 // Tests the handling of the "truncation" flag. |
4703 TEST(HttpCache, WriteResponseInfo_Truncated) { | 4714 TEST(HttpCache, WriteResponseInfo_Truncated) { |
4704 MockHttpCache cache; | 4715 MockHttpCache cache; |
4705 disk_cache::Entry* entry; | 4716 disk_cache::Entry* entry; |
4706 ASSERT_TRUE(cache.CreateBackendEntry("http://www.google.com", &entry, | 4717 ASSERT_TRUE(cache.CreateBackendEntry("http://www.google.com", &entry, NULL)); |
4707 NULL)); | |
4708 | 4718 |
4709 std::string headers("HTTP/1.1 200 OK"); | 4719 std::string headers("HTTP/1.1 200 OK"); |
4710 headers = net::HttpUtil::AssembleRawHeaders(headers.data(), headers.size()); | 4720 headers = net::HttpUtil::AssembleRawHeaders(headers.data(), headers.size()); |
4711 net::HttpResponseInfo response; | 4721 net::HttpResponseInfo response; |
4712 response.headers = new net::HttpResponseHeaders(headers); | 4722 response.headers = new net::HttpResponseHeaders(headers); |
4713 | 4723 |
4714 // Set the last argument for this to be an incomplete request. | 4724 // Set the last argument for this to be an incomplete request. |
4715 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, true)); | 4725 EXPECT_TRUE(MockHttpCache::WriteResponseInfo(entry, &response, true, true)); |
4716 bool truncated = false; | 4726 bool truncated = false; |
4717 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); | 4727 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4897 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); | 4907 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
4898 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 4908 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
4899 EXPECT_FALSE(c->callback.have_result()); | 4909 EXPECT_FALSE(c->callback.have_result()); |
4900 | 4910 |
4901 MockHttpCache::SetTestMode(TEST_MODE_SYNC_ALL); | 4911 MockHttpCache::SetTestMode(TEST_MODE_SYNC_ALL); |
4902 | 4912 |
4903 // Destroy the transaction. | 4913 // Destroy the transaction. |
4904 c->trans.reset(); | 4914 c->trans.reset(); |
4905 MockHttpCache::SetTestMode(0); | 4915 MockHttpCache::SetTestMode(0); |
4906 | 4916 |
4907 | |
4908 // Make sure that we don't invoke the callback. We may have an issue if the | 4917 // Make sure that we don't invoke the callback. We may have an issue if the |
4909 // UrlRequestJob is killed directly (without cancelling the UrlRequest) so we | 4918 // UrlRequestJob is killed directly (without cancelling the UrlRequest) so we |
4910 // could end up with the transaction being deleted twice if we send any | 4919 // could end up with the transaction being deleted twice if we send any |
4911 // notification from the transaction destructor (see http://crbug.com/31723). | 4920 // notification from the transaction destructor (see http://crbug.com/31723). |
4912 EXPECT_FALSE(c->callback.have_result()); | 4921 EXPECT_FALSE(c->callback.have_result()); |
4913 | 4922 |
4914 // Verify that the entry is marked as incomplete. | 4923 // Verify that the entry is marked as incomplete. |
4915 disk_cache::Entry* entry; | 4924 disk_cache::Entry* entry; |
4916 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); | 4925 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); |
4917 net::HttpResponseInfo response; | 4926 net::HttpResponseInfo response; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4960 entry->Close(); | 4969 entry->Close(); |
4961 | 4970 |
4962 RemoveMockTransaction(&transaction); | 4971 RemoveMockTransaction(&transaction); |
4963 } | 4972 } |
4964 | 4973 |
4965 // Tests that we can continue with a request that was interrupted. | 4974 // Tests that we can continue with a request that was interrupted. |
4966 TEST(HttpCache, GET_IncompleteResource) { | 4975 TEST(HttpCache, GET_IncompleteResource) { |
4967 MockHttpCache cache; | 4976 MockHttpCache cache; |
4968 AddMockTransaction(&kRangeGET_TransactionOK); | 4977 AddMockTransaction(&kRangeGET_TransactionOK); |
4969 | 4978 |
4970 std::string raw_headers("HTTP/1.1 200 OK\n" | 4979 std::string raw_headers( |
4971 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 4980 "HTTP/1.1 200 OK\n" |
4972 "ETag: \"foo\"\n" | 4981 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
4973 "Accept-Ranges: bytes\n" | 4982 "ETag: \"foo\"\n" |
4974 "Content-Length: 80\n"); | 4983 "Accept-Ranges: bytes\n" |
| 4984 "Content-Length: 80\n"); |
4975 CreateTruncatedEntry(raw_headers, &cache); | 4985 CreateTruncatedEntry(raw_headers, &cache); |
4976 | 4986 |
4977 // Now make a regular request. | 4987 // Now make a regular request. |
4978 std::string headers; | 4988 std::string headers; |
4979 MockTransaction transaction(kRangeGET_TransactionOK); | 4989 MockTransaction transaction(kRangeGET_TransactionOK); |
4980 transaction.request_headers = EXTRA_HEADER; | 4990 transaction.request_headers = EXTRA_HEADER; |
4981 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 4991 transaction.data = |
4982 "rg: 50-59 rg: 60-69 rg: 70-79 "; | 4992 "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " |
| 4993 "rg: 50-59 rg: 60-69 rg: 70-79 "; |
4983 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 4994 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
4984 | 4995 |
4985 // We update the headers with the ones received while revalidating. | 4996 // We update the headers with the ones received while revalidating. |
4986 std::string expected_headers( | 4997 std::string expected_headers( |
4987 "HTTP/1.1 200 OK\n" | 4998 "HTTP/1.1 200 OK\n" |
4988 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 4999 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
4989 "Accept-Ranges: bytes\n" | 5000 "Accept-Ranges: bytes\n" |
4990 "ETag: \"foo\"\n" | 5001 "ETag: \"foo\"\n" |
4991 "Content-Length: 80\n"); | 5002 "Content-Length: 80\n"); |
4992 | 5003 |
(...skipping 13 matching lines...) Expand all Loading... |
5006 entry->Close(); | 5017 entry->Close(); |
5007 | 5018 |
5008 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5019 RemoveMockTransaction(&kRangeGET_TransactionOK); |
5009 } | 5020 } |
5010 | 5021 |
5011 // Tests the handling of no-store when revalidating a truncated entry. | 5022 // Tests the handling of no-store when revalidating a truncated entry. |
5012 TEST(HttpCache, GET_IncompleteResource_NoStore) { | 5023 TEST(HttpCache, GET_IncompleteResource_NoStore) { |
5013 MockHttpCache cache; | 5024 MockHttpCache cache; |
5014 AddMockTransaction(&kRangeGET_TransactionOK); | 5025 AddMockTransaction(&kRangeGET_TransactionOK); |
5015 | 5026 |
5016 std::string raw_headers("HTTP/1.1 200 OK\n" | 5027 std::string raw_headers( |
5017 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 5028 "HTTP/1.1 200 OK\n" |
5018 "ETag: \"foo\"\n" | 5029 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
5019 "Accept-Ranges: bytes\n" | 5030 "ETag: \"foo\"\n" |
5020 "Content-Length: 80\n"); | 5031 "Accept-Ranges: bytes\n" |
| 5032 "Content-Length: 80\n"); |
5021 CreateTruncatedEntry(raw_headers, &cache); | 5033 CreateTruncatedEntry(raw_headers, &cache); |
5022 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5034 RemoveMockTransaction(&kRangeGET_TransactionOK); |
5023 | 5035 |
5024 // Now make a regular request. | 5036 // Now make a regular request. |
5025 MockTransaction transaction(kRangeGET_TransactionOK); | 5037 MockTransaction transaction(kRangeGET_TransactionOK); |
5026 transaction.request_headers = EXTRA_HEADER; | 5038 transaction.request_headers = EXTRA_HEADER; |
5027 std::string response_headers(transaction.response_headers); | 5039 std::string response_headers(transaction.response_headers); |
5028 response_headers += ("Cache-Control: no-store\n"); | 5040 response_headers += ("Cache-Control: no-store\n"); |
5029 transaction.response_headers = response_headers.c_str(); | 5041 transaction.response_headers = response_headers.c_str(); |
5030 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 5042 transaction.data = |
5031 "rg: 50-59 rg: 60-69 rg: 70-79 "; | 5043 "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " |
| 5044 "rg: 50-59 rg: 60-69 rg: 70-79 "; |
5032 AddMockTransaction(&transaction); | 5045 AddMockTransaction(&transaction); |
5033 | 5046 |
5034 std::string headers; | 5047 std::string headers; |
5035 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 5048 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
5036 | 5049 |
5037 // We update the headers with the ones received while revalidating. | 5050 // We update the headers with the ones received while revalidating. |
5038 std::string expected_headers( | 5051 std::string expected_headers( |
5039 "HTTP/1.1 200 OK\n" | 5052 "HTTP/1.1 200 OK\n" |
5040 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 5053 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
5041 "Accept-Ranges: bytes\n" | 5054 "Accept-Ranges: bytes\n" |
(...skipping 10 matching lines...) Expand all Loading... |
5052 disk_cache::Entry* entry; | 5065 disk_cache::Entry* entry; |
5053 EXPECT_FALSE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry)); | 5066 EXPECT_FALSE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry)); |
5054 RemoveMockTransaction(&transaction); | 5067 RemoveMockTransaction(&transaction); |
5055 } | 5068 } |
5056 | 5069 |
5057 // Tests cancelling a request after the server sent no-store. | 5070 // Tests cancelling a request after the server sent no-store. |
5058 TEST(HttpCache, GET_IncompleteResource_Cancel) { | 5071 TEST(HttpCache, GET_IncompleteResource_Cancel) { |
5059 MockHttpCache cache; | 5072 MockHttpCache cache; |
5060 AddMockTransaction(&kRangeGET_TransactionOK); | 5073 AddMockTransaction(&kRangeGET_TransactionOK); |
5061 | 5074 |
5062 std::string raw_headers("HTTP/1.1 200 OK\n" | 5075 std::string raw_headers( |
5063 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 5076 "HTTP/1.1 200 OK\n" |
5064 "ETag: \"foo\"\n" | 5077 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
5065 "Accept-Ranges: bytes\n" | 5078 "ETag: \"foo\"\n" |
5066 "Content-Length: 80\n"); | 5079 "Accept-Ranges: bytes\n" |
| 5080 "Content-Length: 80\n"); |
5067 CreateTruncatedEntry(raw_headers, &cache); | 5081 CreateTruncatedEntry(raw_headers, &cache); |
5068 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5082 RemoveMockTransaction(&kRangeGET_TransactionOK); |
5069 | 5083 |
5070 // Now make a regular request. | 5084 // Now make a regular request. |
5071 MockTransaction transaction(kRangeGET_TransactionOK); | 5085 MockTransaction transaction(kRangeGET_TransactionOK); |
5072 transaction.request_headers = EXTRA_HEADER; | 5086 transaction.request_headers = EXTRA_HEADER; |
5073 std::string response_headers(transaction.response_headers); | 5087 std::string response_headers(transaction.response_headers); |
5074 response_headers += ("Cache-Control: no-store\n"); | 5088 response_headers += ("Cache-Control: no-store\n"); |
5075 transaction.response_headers = response_headers.c_str(); | 5089 transaction.response_headers = response_headers.c_str(); |
5076 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 5090 transaction.data = |
5077 "rg: 50-59 rg: 60-69 rg: 70-79 "; | 5091 "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " |
| 5092 "rg: 50-59 rg: 60-69 rg: 70-79 "; |
5078 AddMockTransaction(&transaction); | 5093 AddMockTransaction(&transaction); |
5079 | 5094 |
5080 MockHttpRequest request(transaction); | 5095 MockHttpRequest request(transaction); |
5081 Context* c = new Context(); | 5096 Context* c = new Context(); |
5082 | 5097 |
5083 int rv = cache.CreateTransaction(&c->trans); | 5098 int rv = cache.CreateTransaction(&c->trans); |
5084 ASSERT_EQ(net::OK, rv); | 5099 ASSERT_EQ(net::OK, rv); |
5085 | 5100 |
5086 // Queue another request to this transaction. We have to start this request | 5101 // Queue another request to this transaction. We have to start this request |
5087 // before the first one gets the response from the server and dooms the entry, | 5102 // before the first one gets the response from the server and dooms the entry, |
5088 // otherwise it will just create a new entry without being queued to the first | 5103 // otherwise it will just create a new entry without being queued to the first |
5089 // request. | 5104 // request. |
5090 Context* pending = new Context(); | 5105 Context* pending = new Context(); |
5091 ASSERT_EQ(net::OK, cache.CreateTransaction(&pending->trans)); | 5106 ASSERT_EQ(net::OK, cache.CreateTransaction(&pending->trans)); |
5092 | 5107 |
5093 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 5108 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
5094 EXPECT_EQ(net::ERR_IO_PENDING, | 5109 EXPECT_EQ(net::ERR_IO_PENDING, |
5095 pending->trans->Start(&request, pending->callback.callback(), | 5110 pending->trans->Start( |
5096 net::BoundNetLog())); | 5111 &request, pending->callback.callback(), net::BoundNetLog())); |
5097 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); | 5112 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); |
5098 | 5113 |
5099 // Make sure that the entry has some data stored. | 5114 // Make sure that the entry has some data stored. |
5100 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5)); | 5115 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5)); |
5101 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); | 5116 rv = c->trans->Read(buf.get(), buf->size(), c->callback.callback()); |
5102 EXPECT_EQ(5, c->callback.GetResult(rv)); | 5117 EXPECT_EQ(5, c->callback.GetResult(rv)); |
5103 | 5118 |
5104 // Cancel the requests. | 5119 // Cancel the requests. |
5105 delete c; | 5120 delete c; |
5106 delete pending; | 5121 delete pending; |
5107 | 5122 |
5108 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 5123 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
5109 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 5124 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
5110 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 5125 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
5111 | 5126 |
5112 base::MessageLoop::current()->RunUntilIdle(); | 5127 base::MessageLoop::current()->RunUntilIdle(); |
5113 RemoveMockTransaction(&transaction); | 5128 RemoveMockTransaction(&transaction); |
5114 } | 5129 } |
5115 | 5130 |
5116 // Tests that we delete truncated entries if the server changes its mind midway. | 5131 // Tests that we delete truncated entries if the server changes its mind midway. |
5117 TEST(HttpCache, GET_IncompleteResource2) { | 5132 TEST(HttpCache, GET_IncompleteResource2) { |
5118 MockHttpCache cache; | 5133 MockHttpCache cache; |
5119 AddMockTransaction(&kRangeGET_TransactionOK); | 5134 AddMockTransaction(&kRangeGET_TransactionOK); |
5120 | 5135 |
5121 // Content-length will be intentionally bad. | 5136 // Content-length will be intentionally bad. |
5122 std::string raw_headers("HTTP/1.1 200 OK\n" | 5137 std::string raw_headers( |
5123 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 5138 "HTTP/1.1 200 OK\n" |
5124 "ETag: \"foo\"\n" | 5139 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
5125 "Accept-Ranges: bytes\n" | 5140 "ETag: \"foo\"\n" |
5126 "Content-Length: 50\n"); | 5141 "Accept-Ranges: bytes\n" |
| 5142 "Content-Length: 50\n"); |
5127 CreateTruncatedEntry(raw_headers, &cache); | 5143 CreateTruncatedEntry(raw_headers, &cache); |
5128 | 5144 |
5129 // Now make a regular request. We expect the code to fail the validation and | 5145 // Now make a regular request. We expect the code to fail the validation and |
5130 // retry the request without using byte ranges. | 5146 // retry the request without using byte ranges. |
5131 std::string headers; | 5147 std::string headers; |
5132 MockTransaction transaction(kRangeGET_TransactionOK); | 5148 MockTransaction transaction(kRangeGET_TransactionOK); |
5133 transaction.request_headers = EXTRA_HEADER; | 5149 transaction.request_headers = EXTRA_HEADER; |
5134 transaction.data = "Not a range"; | 5150 transaction.data = "Not a range"; |
5135 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 5151 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
5136 | 5152 |
(...skipping 12 matching lines...) Expand all Loading... |
5149 ASSERT_FALSE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry)); | 5165 ASSERT_FALSE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry)); |
5150 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5166 RemoveMockTransaction(&kRangeGET_TransactionOK); |
5151 } | 5167 } |
5152 | 5168 |
5153 // Tests that we always validate a truncated request. | 5169 // Tests that we always validate a truncated request. |
5154 TEST(HttpCache, GET_IncompleteResource3) { | 5170 TEST(HttpCache, GET_IncompleteResource3) { |
5155 MockHttpCache cache; | 5171 MockHttpCache cache; |
5156 AddMockTransaction(&kRangeGET_TransactionOK); | 5172 AddMockTransaction(&kRangeGET_TransactionOK); |
5157 | 5173 |
5158 // This should not require validation for 10 hours. | 5174 // This should not require validation for 10 hours. |
5159 std::string raw_headers("HTTP/1.1 200 OK\n" | 5175 std::string raw_headers( |
5160 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" | 5176 "HTTP/1.1 200 OK\n" |
5161 "ETag: \"foo\"\n" | 5177 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" |
5162 "Cache-Control: max-age= 36000\n" | 5178 "ETag: \"foo\"\n" |
5163 "Accept-Ranges: bytes\n" | 5179 "Cache-Control: max-age= 36000\n" |
5164 "Content-Length: 80\n"); | 5180 "Accept-Ranges: bytes\n" |
| 5181 "Content-Length: 80\n"); |
5165 CreateTruncatedEntry(raw_headers, &cache); | 5182 CreateTruncatedEntry(raw_headers, &cache); |
5166 | 5183 |
5167 // Now make a regular request. | 5184 // Now make a regular request. |
5168 std::string headers; | 5185 std::string headers; |
5169 MockTransaction transaction(kRangeGET_TransactionOK); | 5186 MockTransaction transaction(kRangeGET_TransactionOK); |
5170 transaction.request_headers = EXTRA_HEADER; | 5187 transaction.request_headers = EXTRA_HEADER; |
5171 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 5188 transaction.data = |
5172 "rg: 50-59 rg: 60-69 rg: 70-79 "; | 5189 "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " |
| 5190 "rg: 50-59 rg: 60-69 rg: 70-79 "; |
5173 | 5191 |
5174 scoped_ptr<Context> c(new Context); | 5192 scoped_ptr<Context> c(new Context); |
5175 int rv = cache.CreateTransaction(&c->trans); | 5193 int rv = cache.CreateTransaction(&c->trans); |
5176 ASSERT_EQ(net::OK, rv); | 5194 ASSERT_EQ(net::OK, rv); |
5177 | 5195 |
5178 MockHttpRequest request(transaction); | 5196 MockHttpRequest request(transaction); |
5179 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 5197 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
5180 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); | 5198 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); |
5181 | 5199 |
5182 // We should have checked with the server before finishing Start(). | 5200 // We should have checked with the server before finishing Start(). |
5183 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 5201 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
5184 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 5202 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
5185 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5203 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
5186 | 5204 |
5187 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5205 RemoveMockTransaction(&kRangeGET_TransactionOK); |
5188 } | 5206 } |
5189 | 5207 |
5190 // Tests that we handle 401s for truncated resources. | 5208 // Tests that we handle 401s for truncated resources. |
5191 TEST(HttpCache, GET_IncompleteResourceWithAuth) { | 5209 TEST(HttpCache, GET_IncompleteResourceWithAuth) { |
5192 MockHttpCache cache; | 5210 MockHttpCache cache; |
5193 AddMockTransaction(&kRangeGET_TransactionOK); | 5211 AddMockTransaction(&kRangeGET_TransactionOK); |
5194 | 5212 |
5195 std::string raw_headers("HTTP/1.1 200 OK\n" | 5213 std::string raw_headers( |
5196 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 5214 "HTTP/1.1 200 OK\n" |
5197 "ETag: \"foo\"\n" | 5215 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
5198 "Accept-Ranges: bytes\n" | 5216 "ETag: \"foo\"\n" |
5199 "Content-Length: 80\n"); | 5217 "Accept-Ranges: bytes\n" |
| 5218 "Content-Length: 80\n"); |
5200 CreateTruncatedEntry(raw_headers, &cache); | 5219 CreateTruncatedEntry(raw_headers, &cache); |
5201 | 5220 |
5202 // Now make a regular request. | 5221 // Now make a regular request. |
5203 MockTransaction transaction(kRangeGET_TransactionOK); | 5222 MockTransaction transaction(kRangeGET_TransactionOK); |
5204 transaction.request_headers = "X-Require-Mock-Auth: dummy\r\n" | 5223 transaction.request_headers = "X-Require-Mock-Auth: dummy\r\n" EXTRA_HEADER; |
5205 EXTRA_HEADER; | 5224 transaction.data = |
5206 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 5225 "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " |
5207 "rg: 50-59 rg: 60-69 rg: 70-79 "; | 5226 "rg: 50-59 rg: 60-69 rg: 70-79 "; |
5208 RangeTransactionServer handler; | 5227 RangeTransactionServer handler; |
5209 | 5228 |
5210 scoped_ptr<Context> c(new Context); | 5229 scoped_ptr<Context> c(new Context); |
5211 int rv = cache.CreateTransaction(&c->trans); | 5230 int rv = cache.CreateTransaction(&c->trans); |
5212 ASSERT_EQ(net::OK, rv); | 5231 ASSERT_EQ(net::OK, rv); |
5213 | 5232 |
5214 MockHttpRequest request(transaction); | 5233 MockHttpRequest request(transaction); |
5215 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 5234 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
5216 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); | 5235 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); |
5217 | 5236 |
5218 const net::HttpResponseInfo* response = c->trans->GetResponseInfo(); | 5237 const net::HttpResponseInfo* response = c->trans->GetResponseInfo(); |
5219 ASSERT_TRUE(response); | 5238 ASSERT_TRUE(response); |
5220 ASSERT_EQ(401, response->headers->response_code()); | 5239 ASSERT_EQ(401, response->headers->response_code()); |
5221 rv = c->trans->RestartWithAuth(net::AuthCredentials(), | 5240 rv = |
5222 c->callback.callback()); | 5241 c->trans->RestartWithAuth(net::AuthCredentials(), c->callback.callback()); |
5223 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); | 5242 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); |
5224 response = c->trans->GetResponseInfo(); | 5243 response = c->trans->GetResponseInfo(); |
5225 ASSERT_TRUE(response); | 5244 ASSERT_TRUE(response); |
5226 ASSERT_EQ(200, response->headers->response_code()); | 5245 ASSERT_EQ(200, response->headers->response_code()); |
5227 | 5246 |
5228 ReadAndVerifyTransaction(c->trans.get(), transaction); | 5247 ReadAndVerifyTransaction(c->trans.get(), transaction); |
5229 c.reset(); // The destructor could delete the entry. | 5248 c.reset(); // The destructor could delete the entry. |
5230 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 5249 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
5231 | 5250 |
5232 // Verify that the entry was not deleted. | 5251 // Verify that the entry was not deleted. |
5233 disk_cache::Entry* entry; | 5252 disk_cache::Entry* entry; |
5234 ASSERT_TRUE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry)); | 5253 ASSERT_TRUE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry)); |
5235 entry->Close(); | 5254 entry->Close(); |
5236 | 5255 |
5237 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5256 RemoveMockTransaction(&kRangeGET_TransactionOK); |
5238 } | 5257 } |
5239 | 5258 |
5240 // Tests that we cache a 200 response to the validation request. | 5259 // Tests that we cache a 200 response to the validation request. |
5241 TEST(HttpCache, GET_IncompleteResource4) { | 5260 TEST(HttpCache, GET_IncompleteResource4) { |
5242 MockHttpCache cache; | 5261 MockHttpCache cache; |
5243 AddMockTransaction(&kRangeGET_TransactionOK); | 5262 AddMockTransaction(&kRangeGET_TransactionOK); |
5244 | 5263 |
5245 std::string raw_headers("HTTP/1.1 200 OK\n" | 5264 std::string raw_headers( |
5246 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" | 5265 "HTTP/1.1 200 OK\n" |
5247 "ETag: \"foo\"\n" | 5266 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" |
5248 "Accept-Ranges: bytes\n" | 5267 "ETag: \"foo\"\n" |
5249 "Content-Length: 80\n"); | 5268 "Accept-Ranges: bytes\n" |
| 5269 "Content-Length: 80\n"); |
5250 CreateTruncatedEntry(raw_headers, &cache); | 5270 CreateTruncatedEntry(raw_headers, &cache); |
5251 | 5271 |
5252 // Now make a regular request. | 5272 // Now make a regular request. |
5253 std::string headers; | 5273 std::string headers; |
5254 MockTransaction transaction(kRangeGET_TransactionOK); | 5274 MockTransaction transaction(kRangeGET_TransactionOK); |
5255 transaction.request_headers = EXTRA_HEADER; | 5275 transaction.request_headers = EXTRA_HEADER; |
5256 transaction.data = "Not a range"; | 5276 transaction.data = "Not a range"; |
5257 RangeTransactionServer handler; | 5277 RangeTransactionServer handler; |
5258 handler.set_bad_200(true); | 5278 handler.set_bad_200(true); |
5259 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 5279 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
(...skipping 14 matching lines...) Expand all Loading... |
5274 | 5294 |
5275 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5295 RemoveMockTransaction(&kRangeGET_TransactionOK); |
5276 } | 5296 } |
5277 | 5297 |
5278 // Tests that when we cancel a request that was interrupted, we mark it again | 5298 // Tests that when we cancel a request that was interrupted, we mark it again |
5279 // as truncated. | 5299 // as truncated. |
5280 TEST(HttpCache, GET_CancelIncompleteResource) { | 5300 TEST(HttpCache, GET_CancelIncompleteResource) { |
5281 MockHttpCache cache; | 5301 MockHttpCache cache; |
5282 AddMockTransaction(&kRangeGET_TransactionOK); | 5302 AddMockTransaction(&kRangeGET_TransactionOK); |
5283 | 5303 |
5284 std::string raw_headers("HTTP/1.1 200 OK\n" | 5304 std::string raw_headers( |
5285 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" | 5305 "HTTP/1.1 200 OK\n" |
5286 "ETag: \"foo\"\n" | 5306 "Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n" |
5287 "Accept-Ranges: bytes\n" | 5307 "ETag: \"foo\"\n" |
5288 "Content-Length: 80\n"); | 5308 "Accept-Ranges: bytes\n" |
| 5309 "Content-Length: 80\n"); |
5289 CreateTruncatedEntry(raw_headers, &cache); | 5310 CreateTruncatedEntry(raw_headers, &cache); |
5290 | 5311 |
5291 // Now make a regular request. | 5312 // Now make a regular request. |
5292 MockTransaction transaction(kRangeGET_TransactionOK); | 5313 MockTransaction transaction(kRangeGET_TransactionOK); |
5293 transaction.request_headers = EXTRA_HEADER; | 5314 transaction.request_headers = EXTRA_HEADER; |
5294 | 5315 |
5295 MockHttpRequest request(transaction); | 5316 MockHttpRequest request(transaction); |
5296 Context* c = new Context(); | 5317 Context* c = new Context(); |
5297 int rv = cache.CreateTransaction(&c->trans); | 5318 int rv = cache.CreateTransaction(&c->trans); |
5298 ASSERT_EQ(net::OK, rv); | 5319 ASSERT_EQ(net::OK, rv); |
(...skipping 27 matching lines...) Expand all Loading... |
5326 entry->Close(); | 5347 entry->Close(); |
5327 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5348 RemoveMockTransaction(&kRangeGET_TransactionOK); |
5328 } | 5349 } |
5329 | 5350 |
5330 // Tests that we can handle range requests when we have a truncated entry. | 5351 // Tests that we can handle range requests when we have a truncated entry. |
5331 TEST(HttpCache, RangeGET_IncompleteResource) { | 5352 TEST(HttpCache, RangeGET_IncompleteResource) { |
5332 MockHttpCache cache; | 5353 MockHttpCache cache; |
5333 AddMockTransaction(&kRangeGET_TransactionOK); | 5354 AddMockTransaction(&kRangeGET_TransactionOK); |
5334 | 5355 |
5335 // Content-length will be intentionally bogus. | 5356 // Content-length will be intentionally bogus. |
5336 std::string raw_headers("HTTP/1.1 200 OK\n" | 5357 std::string raw_headers( |
5337 "Last-Modified: something\n" | 5358 "HTTP/1.1 200 OK\n" |
5338 "ETag: \"foo\"\n" | 5359 "Last-Modified: something\n" |
5339 "Accept-Ranges: bytes\n" | 5360 "ETag: \"foo\"\n" |
5340 "Content-Length: 10\n"); | 5361 "Accept-Ranges: bytes\n" |
| 5362 "Content-Length: 10\n"); |
5341 CreateTruncatedEntry(raw_headers, &cache); | 5363 CreateTruncatedEntry(raw_headers, &cache); |
5342 | 5364 |
5343 // Now make a range request. | 5365 // Now make a range request. |
5344 std::string headers; | 5366 std::string headers; |
5345 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 5367 RunTransactionTestWithResponse( |
5346 &headers); | 5368 cache.http_cache(), kRangeGET_TransactionOK, &headers); |
5347 | 5369 |
5348 Verify206Response(headers, 40, 49); | 5370 Verify206Response(headers, 40, 49); |
5349 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 5371 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
5350 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 5372 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
5351 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 5373 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
5352 | 5374 |
5353 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5375 RemoveMockTransaction(&kRangeGET_TransactionOK); |
5354 } | 5376 } |
5355 | 5377 |
5356 TEST(HttpCache, SyncRead) { | 5378 TEST(HttpCache, SyncRead) { |
5357 MockHttpCache cache; | 5379 MockHttpCache cache; |
5358 | 5380 |
5359 // This test ensures that a read that completes synchronously does not cause | 5381 // This test ensures that a read that completes synchronously does not cause |
5360 // any problems. | 5382 // any problems. |
5361 | 5383 |
5362 ScopedMockTransaction transaction(kSimpleGET_Transaction); | 5384 ScopedMockTransaction transaction(kSimpleGET_Transaction); |
5363 transaction.test_mode |= (TEST_MODE_SYNC_CACHE_START | | 5385 transaction.test_mode |= |
5364 TEST_MODE_SYNC_CACHE_READ | | 5386 (TEST_MODE_SYNC_CACHE_START | TEST_MODE_SYNC_CACHE_READ | |
5365 TEST_MODE_SYNC_CACHE_WRITE); | 5387 TEST_MODE_SYNC_CACHE_WRITE); |
5366 | 5388 |
5367 MockHttpRequest r1(transaction), | 5389 MockHttpRequest r1(transaction), r2(transaction), r3(transaction); |
5368 r2(transaction), | |
5369 r3(transaction); | |
5370 | 5390 |
5371 TestTransactionConsumer c1(net::DEFAULT_PRIORITY, cache.http_cache()), | 5391 TestTransactionConsumer c1(net::DEFAULT_PRIORITY, cache.http_cache()), |
5372 c2(net::DEFAULT_PRIORITY, cache.http_cache()), | 5392 c2(net::DEFAULT_PRIORITY, cache.http_cache()), |
5373 c3(net::DEFAULT_PRIORITY, cache.http_cache()); | 5393 c3(net::DEFAULT_PRIORITY, cache.http_cache()); |
5374 | 5394 |
5375 c1.Start(&r1, net::BoundNetLog()); | 5395 c1.Start(&r1, net::BoundNetLog()); |
5376 | 5396 |
5377 r2.load_flags |= net::LOAD_ONLY_FROM_CACHE; | 5397 r2.load_flags |= net::LOAD_ONLY_FROM_CACHE; |
5378 c2.Start(&r2, net::BoundNetLog()); | 5398 c2.Start(&r2, net::BoundNetLog()); |
5379 | 5399 |
5380 r3.load_flags |= net::LOAD_ONLY_FROM_CACHE; | 5400 r3.load_flags |= net::LOAD_ONLY_FROM_CACHE; |
5381 c3.Start(&r3, net::BoundNetLog()); | 5401 c3.Start(&r3, net::BoundNetLog()); |
5382 | 5402 |
5383 base::MessageLoop::current()->Run(); | 5403 base::MessageLoop::current()->Run(); |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5680 // get updated on 304. Here we specifically check that the | 5700 // get updated on 304. Here we specifically check that the |
5681 // HttpResponseHeaders::request_time and HttpResponseHeaders::response_time | 5701 // HttpResponseHeaders::request_time and HttpResponseHeaders::response_time |
5682 // fields also gets updated. | 5702 // fields also gets updated. |
5683 // http://crbug.com/20594. | 5703 // http://crbug.com/20594. |
5684 TEST(HttpCache, UpdatesRequestResponseTimeOn304) { | 5704 TEST(HttpCache, UpdatesRequestResponseTimeOn304) { |
5685 MockHttpCache cache; | 5705 MockHttpCache cache; |
5686 | 5706 |
5687 const char* kUrl = "http://foobar"; | 5707 const char* kUrl = "http://foobar"; |
5688 const char* kData = "body"; | 5708 const char* kData = "body"; |
5689 | 5709 |
5690 MockTransaction mock_network_response = { 0 }; | 5710 MockTransaction mock_network_response = {0}; |
5691 mock_network_response.url = kUrl; | 5711 mock_network_response.url = kUrl; |
5692 | 5712 |
5693 AddMockTransaction(&mock_network_response); | 5713 AddMockTransaction(&mock_network_response); |
5694 | 5714 |
5695 // Request |kUrl|, causing |kNetResponse1| to be written to the cache. | 5715 // Request |kUrl|, causing |kNetResponse1| to be written to the cache. |
5696 | 5716 |
5697 MockTransaction request = { 0 }; | 5717 MockTransaction request = {0}; |
5698 request.url = kUrl; | 5718 request.url = kUrl; |
5699 request.method = "GET"; | 5719 request.method = "GET"; |
5700 request.request_headers = "\r\n"; | 5720 request.request_headers = "\r\n"; |
5701 request.data = kData; | 5721 request.data = kData; |
5702 | 5722 |
5703 static const Response kNetResponse1 = { | 5723 static const Response kNetResponse1 = { |
5704 "HTTP/1.1 200 OK", | 5724 "HTTP/1.1 200 OK", |
5705 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 5725 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
5706 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 5726 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
5707 kData | 5727 kData}; |
5708 }; | |
5709 | 5728 |
5710 kNetResponse1.AssignTo(&mock_network_response); | 5729 kNetResponse1.AssignTo(&mock_network_response); |
5711 | 5730 |
5712 RunTransactionTest(cache.http_cache(), request); | 5731 RunTransactionTest(cache.http_cache(), request); |
5713 | 5732 |
5714 // Request |kUrl| again, this time validating the cache and getting | 5733 // Request |kUrl| again, this time validating the cache and getting |
5715 // a 304 back. | 5734 // a 304 back. |
5716 | 5735 |
5717 request.load_flags = net::LOAD_VALIDATE_CACHE; | 5736 request.load_flags = net::LOAD_VALIDATE_CACHE; |
5718 | 5737 |
5719 static const Response kNetResponse2 = { | 5738 static const Response kNetResponse2 = { |
5720 "HTTP/1.1 304 Not Modified", | 5739 "HTTP/1.1 304 Not Modified", "Date: Wed, 22 Jul 2009 03:15:26 GMT\n", ""}; |
5721 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n", | |
5722 "" | |
5723 }; | |
5724 | 5740 |
5725 kNetResponse2.AssignTo(&mock_network_response); | 5741 kNetResponse2.AssignTo(&mock_network_response); |
5726 | 5742 |
5727 base::Time request_time = base::Time() + base::TimeDelta::FromHours(1234); | 5743 base::Time request_time = base::Time() + base::TimeDelta::FromHours(1234); |
5728 base::Time response_time = base::Time() + base::TimeDelta::FromHours(1235); | 5744 base::Time response_time = base::Time() + base::TimeDelta::FromHours(1235); |
5729 | 5745 |
5730 mock_network_response.request_time = request_time; | 5746 mock_network_response.request_time = request_time; |
5731 mock_network_response.response_time = response_time; | 5747 mock_network_response.response_time = response_time; |
5732 | 5748 |
5733 net::HttpResponseInfo response; | 5749 net::HttpResponseInfo response; |
5734 RunTransactionTestWithResponseInfo(cache.http_cache(), request, &response); | 5750 RunTransactionTestWithResponseInfo(cache.http_cache(), request, &response); |
5735 | 5751 |
5736 // The request and response times should have been updated. | 5752 // The request and response times should have been updated. |
5737 EXPECT_EQ(request_time.ToInternalValue(), | 5753 EXPECT_EQ(request_time.ToInternalValue(), |
5738 response.request_time.ToInternalValue()); | 5754 response.request_time.ToInternalValue()); |
5739 EXPECT_EQ(response_time.ToInternalValue(), | 5755 EXPECT_EQ(response_time.ToInternalValue(), |
5740 response.response_time.ToInternalValue()); | 5756 response.response_time.ToInternalValue()); |
5741 | 5757 |
5742 std::string headers; | 5758 std::string headers; |
5743 response.headers->GetNormalizedHeaders(&headers); | 5759 response.headers->GetNormalizedHeaders(&headers); |
5744 | 5760 |
5745 EXPECT_EQ("HTTP/1.1 200 OK\n" | 5761 EXPECT_EQ( |
5746 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 5762 "HTTP/1.1 200 OK\n" |
5747 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 5763 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
5748 headers); | 5764 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
| 5765 headers); |
5749 | 5766 |
5750 RemoveMockTransaction(&mock_network_response); | 5767 RemoveMockTransaction(&mock_network_response); |
5751 } | 5768 } |
5752 | 5769 |
5753 // Tests that we can write metadata to an entry. | 5770 // Tests that we can write metadata to an entry. |
5754 TEST(HttpCache, WriteMetadata_OK) { | 5771 TEST(HttpCache, WriteMetadata_OK) { |
5755 MockHttpCache cache; | 5772 MockHttpCache cache; |
5756 | 5773 |
5757 // Write to the cache | 5774 // Write to the cache |
5758 net::HttpResponseInfo response; | 5775 net::HttpResponseInfo response; |
5759 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, | 5776 RunTransactionTestWithResponseInfo( |
5760 &response); | 5777 cache.http_cache(), kSimpleGET_Transaction, &response); |
5761 EXPECT_TRUE(response.metadata.get() == NULL); | 5778 EXPECT_TRUE(response.metadata.get() == NULL); |
5762 | 5779 |
5763 // Trivial call. | 5780 // Trivial call. |
5764 cache.http_cache()->WriteMetadata(GURL("foo"), net::DEFAULT_PRIORITY, | 5781 cache.http_cache()->WriteMetadata( |
5765 Time::Now(), NULL, 0); | 5782 GURL("foo"), net::DEFAULT_PRIORITY, Time::Now(), NULL, 0); |
5766 | 5783 |
5767 // Write meta data to the same entry. | 5784 // Write meta data to the same entry. |
5768 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(50)); | 5785 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(50)); |
5769 memset(buf->data(), 0, buf->size()); | 5786 memset(buf->data(), 0, buf->size()); |
5770 base::strlcpy(buf->data(), "Hi there", buf->size()); | 5787 base::strlcpy(buf->data(), "Hi there", buf->size()); |
5771 cache.http_cache()->WriteMetadata(GURL(kSimpleGET_Transaction.url), | 5788 cache.http_cache()->WriteMetadata(GURL(kSimpleGET_Transaction.url), |
5772 net::DEFAULT_PRIORITY, | 5789 net::DEFAULT_PRIORITY, |
5773 response.response_time, | 5790 response.response_time, |
5774 buf.get(), | 5791 buf.get(), |
5775 buf->size()); | 5792 buf->size()); |
5776 | 5793 |
5777 // Release the buffer before the operation takes place. | 5794 // Release the buffer before the operation takes place. |
5778 buf = NULL; | 5795 buf = NULL; |
5779 | 5796 |
5780 // Makes sure we finish pending operations. | 5797 // Makes sure we finish pending operations. |
5781 base::MessageLoop::current()->RunUntilIdle(); | 5798 base::MessageLoop::current()->RunUntilIdle(); |
5782 | 5799 |
5783 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, | 5800 RunTransactionTestWithResponseInfo( |
5784 &response); | 5801 cache.http_cache(), kSimpleGET_Transaction, &response); |
5785 ASSERT_TRUE(response.metadata.get() != NULL); | 5802 ASSERT_TRUE(response.metadata.get() != NULL); |
5786 EXPECT_EQ(50, response.metadata->size()); | 5803 EXPECT_EQ(50, response.metadata->size()); |
5787 EXPECT_EQ(0, strcmp(response.metadata->data(), "Hi there")); | 5804 EXPECT_EQ(0, strcmp(response.metadata->data(), "Hi there")); |
5788 | 5805 |
5789 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 5806 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
5790 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 5807 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
5791 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5808 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
5792 } | 5809 } |
5793 | 5810 |
5794 // Tests that we only write metadata to an entry if the time stamp matches. | 5811 // Tests that we only write metadata to an entry if the time stamp matches. |
5795 TEST(HttpCache, WriteMetadata_Fail) { | 5812 TEST(HttpCache, WriteMetadata_Fail) { |
5796 MockHttpCache cache; | 5813 MockHttpCache cache; |
5797 | 5814 |
5798 // Write to the cache | 5815 // Write to the cache |
5799 net::HttpResponseInfo response; | 5816 net::HttpResponseInfo response; |
5800 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, | 5817 RunTransactionTestWithResponseInfo( |
5801 &response); | 5818 cache.http_cache(), kSimpleGET_Transaction, &response); |
5802 EXPECT_TRUE(response.metadata.get() == NULL); | 5819 EXPECT_TRUE(response.metadata.get() == NULL); |
5803 | 5820 |
5804 // Attempt to write meta data to the same entry. | 5821 // Attempt to write meta data to the same entry. |
5805 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(50)); | 5822 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(50)); |
5806 memset(buf->data(), 0, buf->size()); | 5823 memset(buf->data(), 0, buf->size()); |
5807 base::strlcpy(buf->data(), "Hi there", buf->size()); | 5824 base::strlcpy(buf->data(), "Hi there", buf->size()); |
5808 base::Time expected_time = response.response_time - | 5825 base::Time expected_time = |
5809 base::TimeDelta::FromMilliseconds(20); | 5826 response.response_time - base::TimeDelta::FromMilliseconds(20); |
5810 cache.http_cache()->WriteMetadata(GURL(kSimpleGET_Transaction.url), | 5827 cache.http_cache()->WriteMetadata(GURL(kSimpleGET_Transaction.url), |
5811 net::DEFAULT_PRIORITY, | 5828 net::DEFAULT_PRIORITY, |
5812 expected_time, | 5829 expected_time, |
5813 buf.get(), | 5830 buf.get(), |
5814 buf->size()); | 5831 buf->size()); |
5815 | 5832 |
5816 // Makes sure we finish pending operations. | 5833 // Makes sure we finish pending operations. |
5817 base::MessageLoop::current()->RunUntilIdle(); | 5834 base::MessageLoop::current()->RunUntilIdle(); |
5818 | 5835 |
5819 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, | 5836 RunTransactionTestWithResponseInfo( |
5820 &response); | 5837 cache.http_cache(), kSimpleGET_Transaction, &response); |
5821 EXPECT_TRUE(response.metadata.get() == NULL); | 5838 EXPECT_TRUE(response.metadata.get() == NULL); |
5822 | 5839 |
5823 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 5840 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
5824 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 5841 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
5825 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5842 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
5826 } | 5843 } |
5827 | 5844 |
5828 // Tests that we can read metadata after validating the entry and with READ mode | 5845 // Tests that we can read metadata after validating the entry and with READ mode |
5829 // transactions. | 5846 // transactions. |
5830 TEST(HttpCache, ReadMetadata) { | 5847 TEST(HttpCache, ReadMetadata) { |
5831 MockHttpCache cache; | 5848 MockHttpCache cache; |
5832 | 5849 |
5833 // Write to the cache | 5850 // Write to the cache |
5834 net::HttpResponseInfo response; | 5851 net::HttpResponseInfo response; |
5835 RunTransactionTestWithResponseInfo(cache.http_cache(), | 5852 RunTransactionTestWithResponseInfo( |
5836 kTypicalGET_Transaction, &response); | 5853 cache.http_cache(), kTypicalGET_Transaction, &response); |
5837 EXPECT_TRUE(response.metadata.get() == NULL); | 5854 EXPECT_TRUE(response.metadata.get() == NULL); |
5838 | 5855 |
5839 // Write meta data to the same entry. | 5856 // Write meta data to the same entry. |
5840 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(50)); | 5857 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(50)); |
5841 memset(buf->data(), 0, buf->size()); | 5858 memset(buf->data(), 0, buf->size()); |
5842 base::strlcpy(buf->data(), "Hi there", buf->size()); | 5859 base::strlcpy(buf->data(), "Hi there", buf->size()); |
5843 cache.http_cache()->WriteMetadata(GURL(kTypicalGET_Transaction.url), | 5860 cache.http_cache()->WriteMetadata(GURL(kTypicalGET_Transaction.url), |
5844 net::DEFAULT_PRIORITY, | 5861 net::DEFAULT_PRIORITY, |
5845 response.response_time, | 5862 response.response_time, |
5846 buf.get(), | 5863 buf.get(), |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6072 net::TestCompletionCallback callback; | 6089 net::TestCompletionCallback callback; |
6073 MockHttpRequest request(kSimpleGET_Transaction); | 6090 MockHttpRequest request(kSimpleGET_Transaction); |
6074 | 6091 |
6075 { | 6092 { |
6076 scoped_ptr<net::HttpTransaction> trans; | 6093 scoped_ptr<net::HttpTransaction> trans; |
6077 ASSERT_EQ(net::OK, cache.CreateTransaction(&trans)); | 6094 ASSERT_EQ(net::OK, cache.CreateTransaction(&trans)); |
6078 | 6095 |
6079 // Force a response that can be resumed. | 6096 // Force a response that can be resumed. |
6080 MockTransaction mock_transaction(kSimpleGET_Transaction); | 6097 MockTransaction mock_transaction(kSimpleGET_Transaction); |
6081 AddMockTransaction(&mock_transaction); | 6098 AddMockTransaction(&mock_transaction); |
6082 mock_transaction.response_headers = "Cache-Control: max-age=10000\n" | 6099 mock_transaction.response_headers = |
6083 "Content-Length: 42\n" | 6100 "Cache-Control: max-age=10000\n" |
6084 "Etag: \"foo\"\n"; | 6101 "Content-Length: 42\n" |
| 6102 "Etag: \"foo\"\n"; |
6085 | 6103 |
6086 int rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | 6104 int rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
6087 EXPECT_EQ(net::OK, callback.GetResult(rv)); | 6105 EXPECT_EQ(net::OK, callback.GetResult(rv)); |
6088 | 6106 |
6089 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); | 6107 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
6090 rv = trans->Read(buf.get(), 10, callback.callback()); | 6108 rv = trans->Read(buf.get(), 10, callback.callback()); |
6091 EXPECT_EQ(callback.GetResult(rv), 10); | 6109 EXPECT_EQ(callback.GetResult(rv), 10); |
6092 | 6110 |
6093 trans->StopCaching(); | 6111 trans->StopCaching(); |
6094 | 6112 |
(...skipping 18 matching lines...) Expand all Loading... |
6113 | 6131 |
6114 // Tests that we handle truncated enries when StopCaching is called. | 6132 // Tests that we handle truncated enries when StopCaching is called. |
6115 TEST(HttpCache, StopCachingTruncatedEntry) { | 6133 TEST(HttpCache, StopCachingTruncatedEntry) { |
6116 MockHttpCache cache; | 6134 MockHttpCache cache; |
6117 net::TestCompletionCallback callback; | 6135 net::TestCompletionCallback callback; |
6118 MockHttpRequest request(kRangeGET_TransactionOK); | 6136 MockHttpRequest request(kRangeGET_TransactionOK); |
6119 request.extra_headers.Clear(); | 6137 request.extra_headers.Clear(); |
6120 request.extra_headers.AddHeaderFromString(EXTRA_HEADER_LINE); | 6138 request.extra_headers.AddHeaderFromString(EXTRA_HEADER_LINE); |
6121 AddMockTransaction(&kRangeGET_TransactionOK); | 6139 AddMockTransaction(&kRangeGET_TransactionOK); |
6122 | 6140 |
6123 std::string raw_headers("HTTP/1.1 200 OK\n" | 6141 std::string raw_headers( |
6124 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 6142 "HTTP/1.1 200 OK\n" |
6125 "ETag: \"foo\"\n" | 6143 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
6126 "Accept-Ranges: bytes\n" | 6144 "ETag: \"foo\"\n" |
6127 "Content-Length: 80\n"); | 6145 "Accept-Ranges: bytes\n" |
| 6146 "Content-Length: 80\n"); |
6128 CreateTruncatedEntry(raw_headers, &cache); | 6147 CreateTruncatedEntry(raw_headers, &cache); |
6129 | 6148 |
6130 { | 6149 { |
6131 // Now make a regular request. | 6150 // Now make a regular request. |
6132 scoped_ptr<net::HttpTransaction> trans; | 6151 scoped_ptr<net::HttpTransaction> trans; |
6133 ASSERT_EQ(net::OK, cache.CreateTransaction(&trans)); | 6152 ASSERT_EQ(net::OK, cache.CreateTransaction(&trans)); |
6134 | 6153 |
6135 int rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); | 6154 int rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); |
6136 EXPECT_EQ(net::OK, callback.GetResult(rv)); | 6155 EXPECT_EQ(net::OK, callback.GetResult(rv)); |
6137 | 6156 |
(...skipping 27 matching lines...) Expand all Loading... |
6165 } | 6184 } |
6166 | 6185 |
6167 // Tests that we detect truncated resources from the net when there is | 6186 // Tests that we detect truncated resources from the net when there is |
6168 // a Content-Length header. | 6187 // a Content-Length header. |
6169 TEST(HttpCache, TruncatedByContentLength) { | 6188 TEST(HttpCache, TruncatedByContentLength) { |
6170 MockHttpCache cache; | 6189 MockHttpCache cache; |
6171 net::TestCompletionCallback callback; | 6190 net::TestCompletionCallback callback; |
6172 | 6191 |
6173 MockTransaction transaction(kSimpleGET_Transaction); | 6192 MockTransaction transaction(kSimpleGET_Transaction); |
6174 AddMockTransaction(&transaction); | 6193 AddMockTransaction(&transaction); |
6175 transaction.response_headers = "Cache-Control: max-age=10000\n" | 6194 transaction.response_headers = |
6176 "Content-Length: 100\n"; | 6195 "Cache-Control: max-age=10000\n" |
| 6196 "Content-Length: 100\n"; |
6177 RunTransactionTest(cache.http_cache(), transaction); | 6197 RunTransactionTest(cache.http_cache(), transaction); |
6178 RemoveMockTransaction(&transaction); | 6198 RemoveMockTransaction(&transaction); |
6179 | 6199 |
6180 // Read from the cache. | 6200 // Read from the cache. |
6181 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 6201 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
6182 | 6202 |
6183 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 6203 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
6184 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 6204 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
6185 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 6205 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
6186 } | 6206 } |
6187 | 6207 |
6188 // Tests that we actually flag entries as truncated when we detect an error | 6208 // Tests that we actually flag entries as truncated when we detect an error |
6189 // from the net. | 6209 // from the net. |
6190 TEST(HttpCache, TruncatedByContentLength2) { | 6210 TEST(HttpCache, TruncatedByContentLength2) { |
6191 MockHttpCache cache; | 6211 MockHttpCache cache; |
6192 net::TestCompletionCallback callback; | 6212 net::TestCompletionCallback callback; |
6193 | 6213 |
6194 MockTransaction transaction(kSimpleGET_Transaction); | 6214 MockTransaction transaction(kSimpleGET_Transaction); |
6195 AddMockTransaction(&transaction); | 6215 AddMockTransaction(&transaction); |
6196 transaction.response_headers = "Cache-Control: max-age=10000\n" | 6216 transaction.response_headers = |
6197 "Content-Length: 100\n" | 6217 "Cache-Control: max-age=10000\n" |
6198 "Etag: \"foo\"\n"; | 6218 "Content-Length: 100\n" |
| 6219 "Etag: \"foo\"\n"; |
6199 RunTransactionTest(cache.http_cache(), transaction); | 6220 RunTransactionTest(cache.http_cache(), transaction); |
6200 RemoveMockTransaction(&transaction); | 6221 RemoveMockTransaction(&transaction); |
6201 | 6222 |
6202 // Verify that the entry is marked as incomplete. | 6223 // Verify that the entry is marked as incomplete. |
6203 disk_cache::Entry* entry; | 6224 disk_cache::Entry* entry; |
6204 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); | 6225 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); |
6205 net::HttpResponseInfo response; | 6226 net::HttpResponseInfo response; |
6206 bool truncated = false; | 6227 bool truncated = false; |
6207 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); | 6228 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); |
6208 EXPECT_TRUE(truncated); | 6229 EXPECT_TRUE(truncated); |
(...skipping 18 matching lines...) Expand all Loading... |
6227 net::HttpRequestInfo info; | 6248 net::HttpRequestInfo info; |
6228 info.url = GURL(kSimpleGET_Transaction.url); | 6249 info.url = GURL(kSimpleGET_Transaction.url); |
6229 net::TestCompletionCallback callback; | 6250 net::TestCompletionCallback callback; |
6230 EXPECT_EQ(net::ERR_IO_PENDING, | 6251 EXPECT_EQ(net::ERR_IO_PENDING, |
6231 trans->Start(&info, callback.callback(), net::BoundNetLog())); | 6252 trans->Start(&info, callback.callback(), net::BoundNetLog())); |
6232 | 6253 |
6233 EXPECT_TRUE(cache.network_layer()->last_transaction()); | 6254 EXPECT_TRUE(cache.network_layer()->last_transaction()); |
6234 if (cache.network_layer()->last_transaction()) { | 6255 if (cache.network_layer()->last_transaction()) { |
6235 EXPECT_EQ(net::LOW, | 6256 EXPECT_EQ(net::LOW, |
6236 cache.network_layer()->last_create_transaction_priority()); | 6257 cache.network_layer()->last_create_transaction_priority()); |
6237 EXPECT_EQ(net::LOW, | 6258 EXPECT_EQ(net::LOW, cache.network_layer()->last_transaction()->priority()); |
6238 cache.network_layer()->last_transaction()->priority()); | |
6239 } | 6259 } |
6240 | 6260 |
6241 trans->SetPriority(net::HIGHEST); | 6261 trans->SetPriority(net::HIGHEST); |
6242 | 6262 |
6243 if (cache.network_layer()->last_transaction()) { | 6263 if (cache.network_layer()->last_transaction()) { |
6244 EXPECT_EQ(net::LOW, | 6264 EXPECT_EQ(net::LOW, |
6245 cache.network_layer()->last_create_transaction_priority()); | 6265 cache.network_layer()->last_create_transaction_priority()); |
6246 EXPECT_EQ(net::HIGHEST, | 6266 EXPECT_EQ(net::HIGHEST, |
6247 cache.network_layer()->last_transaction()->priority()); | 6267 cache.network_layer()->last_transaction()->priority()); |
6248 } | 6268 } |
(...skipping 12 matching lines...) Expand all Loading... |
6261 | 6281 |
6262 EXPECT_FALSE(cache.network_layer()->last_transaction()); | 6282 EXPECT_FALSE(cache.network_layer()->last_transaction()); |
6263 | 6283 |
6264 net::HttpRequestInfo info; | 6284 net::HttpRequestInfo info; |
6265 info.url = GURL(kSimpleGET_Transaction.url); | 6285 info.url = GURL(kSimpleGET_Transaction.url); |
6266 net::TestCompletionCallback callback; | 6286 net::TestCompletionCallback callback; |
6267 EXPECT_EQ(net::ERR_IO_PENDING, | 6287 EXPECT_EQ(net::ERR_IO_PENDING, |
6268 trans->Start(&info, callback.callback(), net::BoundNetLog())); | 6288 trans->Start(&info, callback.callback(), net::BoundNetLog())); |
6269 | 6289 |
6270 ASSERT_TRUE(cache.network_layer()->last_transaction()); | 6290 ASSERT_TRUE(cache.network_layer()->last_transaction()); |
6271 EXPECT_FALSE(cache.network_layer()->last_transaction()-> | 6291 EXPECT_FALSE(cache.network_layer() |
6272 websocket_handshake_stream_create_helper()); | 6292 ->last_transaction() |
| 6293 ->websocket_handshake_stream_create_helper()); |
6273 trans->SetWebSocketHandshakeStreamCreateHelper(&create_helper); | 6294 trans->SetWebSocketHandshakeStreamCreateHelper(&create_helper); |
6274 EXPECT_EQ(&create_helper, | 6295 EXPECT_EQ(&create_helper, |
6275 cache.network_layer()->last_transaction()-> | 6296 cache.network_layer() |
6276 websocket_handshake_stream_create_helper()); | 6297 ->last_transaction() |
| 6298 ->websocket_handshake_stream_create_helper()); |
6277 EXPECT_EQ(net::OK, callback.WaitForResult()); | 6299 EXPECT_EQ(net::OK, callback.WaitForResult()); |
6278 } | 6300 } |
6279 | 6301 |
6280 // Make sure that a cache transaction passes on its priority to | 6302 // Make sure that a cache transaction passes on its priority to |
6281 // newly-created network transactions. | 6303 // newly-created network transactions. |
6282 TEST(HttpCache, SetPriorityNewTransaction) { | 6304 TEST(HttpCache, SetPriorityNewTransaction) { |
6283 MockHttpCache cache; | 6305 MockHttpCache cache; |
6284 AddMockTransaction(&kRangeGET_TransactionOK); | 6306 AddMockTransaction(&kRangeGET_TransactionOK); |
6285 | 6307 |
6286 std::string raw_headers("HTTP/1.1 200 OK\n" | 6308 std::string raw_headers( |
6287 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 6309 "HTTP/1.1 200 OK\n" |
6288 "ETag: \"foo\"\n" | 6310 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
6289 "Accept-Ranges: bytes\n" | 6311 "ETag: \"foo\"\n" |
6290 "Content-Length: 80\n"); | 6312 "Accept-Ranges: bytes\n" |
| 6313 "Content-Length: 80\n"); |
6291 CreateTruncatedEntry(raw_headers, &cache); | 6314 CreateTruncatedEntry(raw_headers, &cache); |
6292 | 6315 |
6293 // Now make a regular request. | 6316 // Now make a regular request. |
6294 std::string headers; | 6317 std::string headers; |
6295 MockTransaction transaction(kRangeGET_TransactionOK); | 6318 MockTransaction transaction(kRangeGET_TransactionOK); |
6296 transaction.request_headers = EXTRA_HEADER; | 6319 transaction.request_headers = EXTRA_HEADER; |
6297 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 6320 transaction.data = |
6298 "rg: 50-59 rg: 60-69 rg: 70-79 "; | 6321 "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " |
| 6322 "rg: 50-59 rg: 60-69 rg: 70-79 "; |
6299 | 6323 |
6300 scoped_ptr<net::HttpTransaction> trans; | 6324 scoped_ptr<net::HttpTransaction> trans; |
6301 ASSERT_EQ(net::OK, | 6325 ASSERT_EQ(net::OK, |
6302 cache.http_cache()->CreateTransaction(net::MEDIUM, &trans)); | 6326 cache.http_cache()->CreateTransaction(net::MEDIUM, &trans)); |
6303 EXPECT_EQ(net::DEFAULT_PRIORITY, | 6327 EXPECT_EQ(net::DEFAULT_PRIORITY, |
6304 cache.network_layer()->last_create_transaction_priority()); | 6328 cache.network_layer()->last_create_transaction_priority()); |
6305 | 6329 |
6306 MockHttpRequest info(transaction); | 6330 MockHttpRequest info(transaction); |
6307 net::TestCompletionCallback callback; | 6331 net::TestCompletionCallback callback; |
6308 EXPECT_EQ(net::ERR_IO_PENDING, | 6332 EXPECT_EQ(net::ERR_IO_PENDING, |
6309 trans->Start(&info, callback.callback(), net::BoundNetLog())); | 6333 trans->Start(&info, callback.callback(), net::BoundNetLog())); |
6310 EXPECT_EQ(net::OK, callback.WaitForResult()); | 6334 EXPECT_EQ(net::OK, callback.WaitForResult()); |
6311 | 6335 |
6312 EXPECT_EQ(net::MEDIUM, | 6336 EXPECT_EQ(net::MEDIUM, |
6313 cache.network_layer()->last_create_transaction_priority()); | 6337 cache.network_layer()->last_create_transaction_priority()); |
6314 | 6338 |
6315 trans->SetPriority(net::HIGHEST); | 6339 trans->SetPriority(net::HIGHEST); |
6316 // Should trigger a new network transaction and pick up the new | 6340 // Should trigger a new network transaction and pick up the new |
6317 // priority. | 6341 // priority. |
6318 ReadAndVerifyTransaction(trans.get(), transaction); | 6342 ReadAndVerifyTransaction(trans.get(), transaction); |
6319 | 6343 |
6320 EXPECT_EQ(net::HIGHEST, | 6344 EXPECT_EQ(net::HIGHEST, |
6321 cache.network_layer()->last_create_transaction_priority()); | 6345 cache.network_layer()->last_create_transaction_priority()); |
6322 | 6346 |
6323 RemoveMockTransaction(&kRangeGET_TransactionOK); | 6347 RemoveMockTransaction(&kRangeGET_TransactionOK); |
6324 } | 6348 } |
6325 | 6349 |
6326 int64 RunTransactionAndGetReceivedBytes( | 6350 int64 RunTransactionAndGetReceivedBytes(MockHttpCache& cache, |
6327 MockHttpCache& cache, | 6351 const MockTransaction& trans_info) { |
6328 const MockTransaction& trans_info) { | |
6329 int64 received_bytes = -1; | 6352 int64 received_bytes = -1; |
6330 RunTransactionTestBase(cache.http_cache(), trans_info, | 6353 RunTransactionTestBase(cache.http_cache(), |
6331 MockHttpRequest(trans_info), NULL, net::BoundNetLog(), | 6354 trans_info, |
6332 NULL, &received_bytes); | 6355 MockHttpRequest(trans_info), |
| 6356 NULL, |
| 6357 net::BoundNetLog(), |
| 6358 NULL, |
| 6359 &received_bytes); |
6333 return received_bytes; | 6360 return received_bytes; |
6334 } | 6361 } |
6335 | 6362 |
6336 int64 TransactionSize(const MockTransaction& transaction) { | 6363 int64 TransactionSize(const MockTransaction& transaction) { |
6337 return strlen(transaction.status) + strlen(transaction.response_headers) + | 6364 return strlen(transaction.status) + strlen(transaction.response_headers) + |
6338 strlen(transaction.data); | 6365 strlen(transaction.data); |
6339 } | 6366 } |
6340 | 6367 |
6341 TEST(HttpCache, ReceivedBytesCacheMissAndThenHit) { | 6368 TEST(HttpCache, ReceivedBytesCacheMissAndThenHit) { |
6342 MockHttpCache cache; | 6369 MockHttpCache cache; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6409 base::MessageLoop::current()->RunUntilIdle(); | 6436 base::MessageLoop::current()->RunUntilIdle(); |
6410 | 6437 |
6411 // Read bytes 20-29 and 50-59 from the network, bytes 30-49 from the cache. | 6438 // Read bytes 20-29 and 50-59 from the network, bytes 30-49 from the cache. |
6412 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; | 6439 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; |
6413 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; | 6440 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; |
6414 received_bytes = RunTransactionAndGetReceivedBytes(cache, transaction); | 6441 received_bytes = RunTransactionAndGetReceivedBytes(cache, transaction); |
6415 EXPECT_EQ(range_response_size * 2, received_bytes); | 6442 EXPECT_EQ(range_response_size * 2, received_bytes); |
6416 | 6443 |
6417 RemoveMockTransaction(&kRangeGET_TransactionOK); | 6444 RemoveMockTransaction(&kRangeGET_TransactionOK); |
6418 } | 6445 } |
OLD | NEW |