| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 net::LoadTimingInfo* load_timing_info) { | 178 net::LoadTimingInfo* load_timing_info) { |
| 179 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), | 179 RunTransactionTestBase(cache, trans_info, MockHttpRequest(trans_info), |
| 180 NULL, log, load_timing_info, NULL); | 180 NULL, log, load_timing_info, NULL); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void RunTransactionTest(net::HttpCache* cache, | 183 void RunTransactionTest(net::HttpCache* cache, |
| 184 const MockTransaction& trans_info) { | 184 const MockTransaction& trans_info) { |
| 185 RunTransactionTestAndGetTiming(cache, trans_info, net::BoundNetLog(), NULL); | 185 RunTransactionTestAndGetTiming(cache, trans_info, net::BoundNetLog(), NULL); |
| 186 } | 186 } |
| 187 | 187 |
| 188 void RunTransactionTestWithLog(net::HttpCache* cache, |
| 189 const MockTransaction& trans_info, |
| 190 const net::BoundNetLog& log) { |
| 191 RunTransactionTestAndGetTiming(cache, trans_info, log, NULL); |
| 192 } |
| 193 |
| 188 void RunTransactionTestWithResponseInfo(net::HttpCache* cache, | 194 void RunTransactionTestWithResponseInfo(net::HttpCache* cache, |
| 189 const MockTransaction& trans_info, | 195 const MockTransaction& trans_info, |
| 190 net::HttpResponseInfo* response) { | 196 net::HttpResponseInfo* response) { |
| 191 RunTransactionTestWithRequest(cache, trans_info, MockHttpRequest(trans_info), | 197 RunTransactionTestWithRequest(cache, trans_info, MockHttpRequest(trans_info), |
| 192 response); | 198 response); |
| 193 } | 199 } |
| 194 | 200 |
| 195 void RunTransactionTestWithResponseInfoAndGetTiming( | 201 void RunTransactionTestWithResponseInfoAndGetTiming( |
| 196 net::HttpCache* cache, | 202 net::HttpCache* cache, |
| 197 const MockTransaction& trans_info, | 203 const MockTransaction& trans_info, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 286 |
| 281 // Returns only 416 or 304 when set. | 287 // Returns only 416 or 304 when set. |
| 282 void set_not_modified(bool value) { not_modified_ = value; } | 288 void set_not_modified(bool value) { not_modified_ = value; } |
| 283 | 289 |
| 284 // Returns 206 when revalidating a range (instead of 304). | 290 // Returns 206 when revalidating a range (instead of 304). |
| 285 void set_modified(bool value) { modified_ = value; } | 291 void set_modified(bool value) { modified_ = value; } |
| 286 | 292 |
| 287 // Returns 200 instead of 206 (a malformed response overall). | 293 // Returns 200 instead of 206 (a malformed response overall). |
| 288 void set_bad_200(bool value) { bad_200_ = value; } | 294 void set_bad_200(bool value) { bad_200_ = value; } |
| 289 | 295 |
| 296 // Other than regular range related behavior (and the flags mentioned above), |
| 297 // the server reacts to requests headers like so: |
| 298 // X-Require-Mock-Auth -> return 401. |
| 299 // X-Return-Default-Range -> assume 40-49 was requested. |
| 290 static void RangeHandler(const net::HttpRequestInfo* request, | 300 static void RangeHandler(const net::HttpRequestInfo* request, |
| 291 std::string* response_status, | 301 std::string* response_status, |
| 292 std::string* response_headers, | 302 std::string* response_headers, |
| 293 std::string* response_data); | 303 std::string* response_data); |
| 294 | 304 |
| 295 private: | 305 private: |
| 296 static bool not_modified_; | 306 static bool not_modified_; |
| 297 static bool modified_; | 307 static bool modified_; |
| 298 static bool bad_200_; | 308 static bool bad_200_; |
| 299 DISALLOW_COPY_AND_ASSIGN(RangeTransactionServer); | 309 DISALLOW_COPY_AND_ASSIGN(RangeTransactionServer); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 ranges.size() != 1) { | 359 ranges.size() != 1) { |
| 350 // This is not a byte range request. We return 200. | 360 // This is not a byte range request. We return 200. |
| 351 response_status->assign("HTTP/1.1 200 OK"); | 361 response_status->assign("HTTP/1.1 200 OK"); |
| 352 response_headers->assign("Date: Wed, 28 Nov 2007 09:40:09 GMT"); | 362 response_headers->assign("Date: Wed, 28 Nov 2007 09:40:09 GMT"); |
| 353 response_data->assign("Not a range"); | 363 response_data->assign("Not a range"); |
| 354 return; | 364 return; |
| 355 } | 365 } |
| 356 | 366 |
| 357 // We can handle this range request. | 367 // We can handle this range request. |
| 358 net::HttpByteRange byte_range = ranges[0]; | 368 net::HttpByteRange byte_range = ranges[0]; |
| 369 |
| 370 if (request->extra_headers.HasHeader("X-Return-Default-Range")) { |
| 371 byte_range.set_first_byte_position(40); |
| 372 byte_range.set_last_byte_position(49); |
| 373 } |
| 374 |
| 359 if (byte_range.first_byte_position() > 79) { | 375 if (byte_range.first_byte_position() > 79) { |
| 360 response_status->assign("HTTP/1.1 416 Requested Range Not Satisfiable"); | 376 response_status->assign("HTTP/1.1 416 Requested Range Not Satisfiable"); |
| 361 response_data->clear(); | 377 response_data->clear(); |
| 362 return; | 378 return; |
| 363 } | 379 } |
| 364 | 380 |
| 365 EXPECT_TRUE(byte_range.ComputeBounds(80)); | 381 EXPECT_TRUE(byte_range.ComputeBounds(80)); |
| 366 int start = static_cast<int>(byte_range.first_byte_position()); | 382 int start = static_cast<int>(byte_range.first_byte_position()); |
| 367 int end = static_cast<int>(byte_range.last_byte_position()); | 383 int end = static_cast<int>(byte_range.last_byte_position()); |
| 368 | 384 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 "Accept-Ranges: bytes\n" | 429 "Accept-Ranges: bytes\n" |
| 414 "Content-Length: 10\n", | 430 "Content-Length: 10\n", |
| 415 base::Time(), | 431 base::Time(), |
| 416 "rg: 40-49 ", | 432 "rg: 40-49 ", |
| 417 TEST_MODE_NORMAL, | 433 TEST_MODE_NORMAL, |
| 418 &RangeTransactionServer::RangeHandler, | 434 &RangeTransactionServer::RangeHandler, |
| 419 0, | 435 0, |
| 420 net::OK | 436 net::OK |
| 421 }; | 437 }; |
| 422 | 438 |
| 439 const char kFullRangeData[] = |
| 440 "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 " |
| 441 "rg: 40-49 rg: 50-59 rg: 60-69 rg: 70-79 "; |
| 442 |
| 423 // Verifies the response headers (|response|) match a partial content | 443 // Verifies the response headers (|response|) match a partial content |
| 424 // response for the range starting at |start| and ending at |end|. | 444 // response for the range starting at |start| and ending at |end|. |
| 425 void Verify206Response(std::string response, int start, int end) { | 445 void Verify206Response(std::string response, int start, int end) { |
| 426 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), | 446 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), |
| 427 response.size())); | 447 response.size())); |
| 428 scoped_refptr<net::HttpResponseHeaders> headers( | 448 scoped_refptr<net::HttpResponseHeaders> headers( |
| 429 new net::HttpResponseHeaders(raw_headers)); | 449 new net::HttpResponseHeaders(raw_headers)); |
| 430 | 450 |
| 431 ASSERT_EQ(206, headers->response_code()); | 451 ASSERT_EQ(206, headers->response_code()); |
| 432 | 452 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 } | 547 } |
| 528 | 548 |
| 529 // Modifies |entries| to only include log entries created by the cache layer and | 549 // Modifies |entries| to only include log entries created by the cache layer and |
| 530 // asserted on in these tests. | 550 // asserted on in these tests. |
| 531 void FilterLogEntries(net::CapturingNetLog::CapturedEntryList* entries) { | 551 void FilterLogEntries(net::CapturingNetLog::CapturedEntryList* entries) { |
| 532 entries->erase(std::remove_if(entries->begin(), entries->end(), | 552 entries->erase(std::remove_if(entries->begin(), entries->end(), |
| 533 &ShouldIgnoreLogEntry), | 553 &ShouldIgnoreLogEntry), |
| 534 entries->end()); | 554 entries->end()); |
| 535 } | 555 } |
| 536 | 556 |
| 557 bool LogContainsEventType(const net::CapturingBoundNetLog& log, |
| 558 net::NetLog::EventType expected) { |
| 559 net::CapturingNetLog::CapturedEntryList entries; |
| 560 log.GetEntries(&entries); |
| 561 for (size_t i = 0; i < entries.size(); i++) { |
| 562 if (entries[i].type == expected) |
| 563 return true; |
| 564 } |
| 565 return false; |
| 566 } |
| 567 |
| 537 } // namespace | 568 } // namespace |
| 538 | 569 |
| 539 | 570 |
| 540 //----------------------------------------------------------------------------- | 571 //----------------------------------------------------------------------------- |
| 541 // Tests. | 572 // Tests. |
| 542 | 573 |
| 543 TEST(HttpCache, CreateThenDestroy) { | 574 TEST(HttpCache, CreateThenDestroy) { |
| 544 MockHttpCache cache; | 575 MockHttpCache cache; |
| 545 | 576 |
| 546 scoped_ptr<net::HttpTransaction> trans; | 577 scoped_ptr<net::HttpTransaction> trans; |
| (...skipping 3073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3620 transaction.request_headers = "If-Range: bla\r\n" | 3651 transaction.request_headers = "If-Range: bla\r\n" |
| 3621 EXTRA_HEADER | 3652 EXTRA_HEADER |
| 3622 "Range: bytes = 40-49\r\n"; | 3653 "Range: bytes = 40-49\r\n"; |
| 3623 RunTransactionTest(cache.http_cache(), transaction); | 3654 RunTransactionTest(cache.http_cache(), transaction); |
| 3624 | 3655 |
| 3625 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 3656 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 3626 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3657 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 3627 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 3658 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 3628 } | 3659 } |
| 3629 | 3660 |
| 3661 TEST(HttpCache, SimpleGET_DoesntLogHeaders) { |
| 3662 MockHttpCache cache; |
| 3663 |
| 3664 net::CapturingBoundNetLog log; |
| 3665 RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, |
| 3666 log.bound()); |
| 3667 |
| 3668 EXPECT_FALSE(LogContainsEventType( |
| 3669 log, net::NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); |
| 3670 } |
| 3671 |
| 3672 TEST(HttpCache, RangeGET_LogsHeaders) { |
| 3673 MockHttpCache cache; |
| 3674 |
| 3675 net::CapturingBoundNetLog log; |
| 3676 RunTransactionTestWithLog(cache.http_cache(), kRangeGET_Transaction, |
| 3677 log.bound()); |
| 3678 |
| 3679 EXPECT_TRUE(LogContainsEventType( |
| 3680 log, net::NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); |
| 3681 } |
| 3682 |
| 3683 TEST(HttpCache, ExternalValidation_LogsHeaders) { |
| 3684 MockHttpCache cache; |
| 3685 |
| 3686 net::CapturingBoundNetLog log; |
| 3687 MockTransaction transaction(kSimpleGET_Transaction); |
| 3688 transaction.request_headers = "If-None-Match: foo\r\n" EXTRA_HEADER; |
| 3689 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); |
| 3690 |
| 3691 EXPECT_TRUE(LogContainsEventType( |
| 3692 log, net::NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); |
| 3693 } |
| 3694 |
| 3695 TEST(HttpCache, SpecialHeaders_LogsHeaders) { |
| 3696 MockHttpCache cache; |
| 3697 |
| 3698 net::CapturingBoundNetLog log; |
| 3699 MockTransaction transaction(kSimpleGET_Transaction); |
| 3700 transaction.request_headers = "cache-control: no-cache\r\n" EXTRA_HEADER; |
| 3701 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); |
| 3702 |
| 3703 EXPECT_TRUE(LogContainsEventType( |
| 3704 log, net::NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS)); |
| 3705 } |
| 3706 |
| 3630 // Tests that receiving 206 for a regular request is handled correctly. | 3707 // Tests that receiving 206 for a regular request is handled correctly. |
| 3631 TEST(HttpCache, GET_Crazy206) { | 3708 TEST(HttpCache, GET_Crazy206) { |
| 3632 MockHttpCache cache; | 3709 MockHttpCache cache; |
| 3633 | 3710 |
| 3634 // Write to the cache. | 3711 // Write to the cache. |
| 3635 MockTransaction transaction(kRangeGET_TransactionOK); | 3712 MockTransaction transaction(kRangeGET_TransactionOK); |
| 3636 AddMockTransaction(&transaction); | 3713 AddMockTransaction(&transaction); |
| 3637 transaction.request_headers = EXTRA_HEADER; | 3714 transaction.request_headers = EXTRA_HEADER; |
| 3638 transaction.handler = NULL; | 3715 transaction.handler = NULL; |
| 3639 RunTransactionTest(cache.http_cache(), transaction); | 3716 RunTransactionTest(cache.http_cache(), transaction); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3661 transaction.status = "HTTP/1.1 416 Requested Range Not Satisfiable"; | 3738 transaction.status = "HTTP/1.1 416 Requested Range Not Satisfiable"; |
| 3662 RunTransactionTest(cache.http_cache(), transaction); | 3739 RunTransactionTest(cache.http_cache(), transaction); |
| 3663 | 3740 |
| 3664 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3741 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 3665 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3742 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 3666 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3743 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 3667 | 3744 |
| 3668 RemoveMockTransaction(&transaction); | 3745 RemoveMockTransaction(&transaction); |
| 3669 } | 3746 } |
| 3670 | 3747 |
| 3671 // Tests that we store partial responses that can't be validated, as they can | 3748 // Tests that we don't store partial responses that can't be validated. |
| 3672 // be used for requests that don't require revalidation. | |
| 3673 TEST(HttpCache, RangeGET_NoStrongValidators) { | 3749 TEST(HttpCache, RangeGET_NoStrongValidators) { |
| 3674 MockHttpCache cache; | 3750 MockHttpCache cache; |
| 3675 std::string headers; | 3751 std::string headers; |
| 3676 | 3752 |
| 3677 // Write to the cache (40-49). | 3753 // Attempt to write to the cache (40-49). |
| 3678 MockTransaction transaction(kRangeGET_TransactionOK); | 3754 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
| 3679 AddMockTransaction(&transaction); | |
| 3680 transaction.response_headers = "Content-Length: 10\n" | 3755 transaction.response_headers = "Content-Length: 10\n" |
| 3681 "Cache-Control: max-age=3600\n" | 3756 "Cache-Control: max-age=3600\n" |
| 3682 "ETag: w/\"foo\"\n"; | 3757 "ETag: w/\"foo\"\n"; |
| 3683 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 3758 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 3684 | 3759 |
| 3685 Verify206Response(headers, 40, 49); | 3760 Verify206Response(headers, 40, 49); |
| 3686 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3761 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 3687 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3762 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 3688 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3763 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 3689 | 3764 |
| 3690 // Now verify that there's cached data. | 3765 // Now verify that there's no cached data. |
| 3691 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 3766 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 3692 &headers); | 3767 &headers); |
| 3693 | 3768 |
| 3694 Verify206Response(headers, 40, 49); | 3769 Verify206Response(headers, 40, 49); |
| 3695 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3770 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 3696 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3771 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 3697 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3772 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 3698 | |
| 3699 RemoveMockTransaction(&transaction); | |
| 3700 } | 3773 } |
| 3701 | 3774 |
| 3702 // Tests failures to validate cache partial responses that lack strong | 3775 // Tests failures to conditionalize byte range requests. |
| 3703 // validators. | 3776 TEST(HttpCache, RangeGET_NoConditionalization) { |
| 3704 TEST(HttpCache, RangeGET_NoValidation) { | |
| 3705 MockHttpCache cache; | 3777 MockHttpCache cache; |
| 3778 cache.FailConditionalizations(); |
| 3706 std::string headers; | 3779 std::string headers; |
| 3707 | 3780 |
| 3708 // Write to the cache (40-49). | 3781 // Write to the cache (40-49). |
| 3709 MockTransaction transaction(kRangeGET_TransactionOK); | 3782 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
| 3710 AddMockTransaction(&transaction); | |
| 3711 transaction.response_headers = "Content-Length: 10\n" | 3783 transaction.response_headers = "Content-Length: 10\n" |
| 3712 "ETag: w/\"foo\"\n"; | 3784 "ETag: \"foo\"\n"; |
| 3713 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 3785 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 3714 | 3786 |
| 3715 Verify206Response(headers, 40, 49); | 3787 Verify206Response(headers, 40, 49); |
| 3788 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 3789 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 3790 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 3791 |
| 3792 // Now verify that the cached data is not used. |
| 3793 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 3794 &headers); |
| 3795 |
| 3796 Verify206Response(headers, 40, 49); |
| 3797 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 3798 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 3799 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 3800 } |
| 3801 |
| 3802 // Tests that restarting a partial request when the cached data cannot be |
| 3803 // revalidated logs an event. |
| 3804 TEST(HttpCache, RangeGET_NoValidation_LogsRestart) { |
| 3805 MockHttpCache cache; |
| 3806 cache.FailConditionalizations(); |
| 3807 |
| 3808 // Write to the cache (40-49). |
| 3809 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
| 3810 transaction.response_headers = "Content-Length: 10\n" |
| 3811 "ETag: \"foo\"\n"; |
| 3812 RunTransactionTest(cache.http_cache(), transaction); |
| 3813 |
| 3814 // Now verify that the cached data is not used. |
| 3815 net::CapturingBoundNetLog log; |
| 3816 RunTransactionTestWithLog(cache.http_cache(), kRangeGET_TransactionOK, |
| 3817 log.bound()); |
| 3818 |
| 3819 EXPECT_TRUE(LogContainsEventType( |
| 3820 log, net::NetLog::TYPE_HTTP_CACHE_RESTART_PARTIAL_REQUEST)); |
| 3821 } |
| 3822 |
| 3823 // Tests that a failure to conditionalize a regular request (no range) with a |
| 3824 // sparse entry results in a full response. |
| 3825 TEST(HttpCache, GET_NoConditionalization) { |
| 3826 MockHttpCache cache; |
| 3827 cache.FailConditionalizations(); |
| 3828 std::string headers; |
| 3829 |
| 3830 // Write to the cache (40-49). |
| 3831 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
| 3832 transaction.response_headers = "Content-Length: 10\n" |
| 3833 "ETag: \"foo\"\n"; |
| 3834 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 3835 |
| 3836 Verify206Response(headers, 40, 49); |
| 3716 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3837 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 3717 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3838 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 3718 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3839 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 3719 | 3840 |
| 3720 // Now verify that the cached data is not used. | 3841 // Now verify that the cached data is not used. |
| 3721 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 3842 // Don't ask for a range. The cache will attempt to use the cached data but |
| 3722 &headers); | 3843 // should discard it as it cannot be validated. A regular request should go |
| 3844 // to the server and a new entry should be created. |
| 3845 transaction.request_headers = EXTRA_HEADER; |
| 3846 transaction.data = "Not a range"; |
| 3847 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 3723 | 3848 |
| 3724 Verify206Response(headers, 40, 49); | 3849 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); |
| 3725 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3850 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 3726 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3851 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 3727 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 3852 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 3728 | 3853 |
| 3729 RemoveMockTransaction(&transaction); | 3854 // The last response was saved. |
| 3855 RunTransactionTest(cache.http_cache(), transaction); |
| 3856 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 3857 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
| 3858 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 3859 } |
| 3860 |
| 3861 // Verifies that conditionalization failures when asking for a range that would |
| 3862 // require the cache to modify the range to ask, result in a network request |
| 3863 // that matches the user's one. |
| 3864 TEST(HttpCache, RangeGET_NoConditionalization2) { |
| 3865 MockHttpCache cache; |
| 3866 cache.FailConditionalizations(); |
| 3867 std::string headers; |
| 3868 |
| 3869 // Write to the cache (40-49). |
| 3870 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
| 3871 transaction.response_headers = "Content-Length: 10\n" |
| 3872 "ETag: \"foo\"\n"; |
| 3873 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 3874 |
| 3875 Verify206Response(headers, 40, 49); |
| 3876 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 3877 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 3878 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 3879 |
| 3880 // Now verify that the cached data is not used. |
| 3881 // Ask for a range that extends before and after the cached data so that the |
| 3882 // cache would normally mix data from three sources. After deleting the entry, |
| 3883 // the response will come from a single network request. |
| 3884 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; |
| 3885 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; |
| 3886 transaction.response_headers = kRangeGET_TransactionOK.response_headers; |
| 3887 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 3888 |
| 3889 Verify206Response(headers, 20, 59); |
| 3890 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 3891 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 3892 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 3893 |
| 3894 // The last response was saved. |
| 3895 RunTransactionTest(cache.http_cache(), transaction); |
| 3896 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 3897 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
| 3898 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 3730 } | 3899 } |
| 3731 | 3900 |
| 3732 // Tests that we cache partial responses that lack content-length. | 3901 // Tests that we cache partial responses that lack content-length. |
| 3733 TEST(HttpCache, RangeGET_NoContentLength) { | 3902 TEST(HttpCache, RangeGET_NoContentLength) { |
| 3734 MockHttpCache cache; | 3903 MockHttpCache cache; |
| 3735 std::string headers; | 3904 std::string headers; |
| 3736 | 3905 |
| 3737 // Attempt to write to the cache (40-49). | 3906 // Attempt to write to the cache (40-49). |
| 3738 MockTransaction transaction(kRangeGET_TransactionOK); | 3907 MockTransaction transaction(kRangeGET_TransactionOK); |
| 3739 AddMockTransaction(&transaction); | 3908 AddMockTransaction(&transaction); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3813 | 3982 |
| 3814 Verify206Response(headers, 20, 59); | 3983 Verify206Response(headers, 20, 59); |
| 3815 EXPECT_EQ(4, cache.network_layer()->transaction_count()); | 3984 EXPECT_EQ(4, cache.network_layer()->transaction_count()); |
| 3816 EXPECT_EQ(3, cache.disk_cache()->open_count()); | 3985 EXPECT_EQ(3, cache.disk_cache()->open_count()); |
| 3817 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3986 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 3818 TestLoadTimingNetworkRequest(load_timing_info); | 3987 TestLoadTimingNetworkRequest(load_timing_info); |
| 3819 | 3988 |
| 3820 RemoveMockTransaction(&kRangeGET_TransactionOK); | 3989 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 3821 } | 3990 } |
| 3822 | 3991 |
| 3823 // Checks that with a cache backend having Sparse IO unimplementes the cache | |
| 3824 // entry would be doomed after a range request. | |
| 3825 // TODO(pasko): remove when the SimpleBackendImpl implements Sparse IO. | |
| 3826 TEST(HttpCache, RangeGET_SparseNotImplemented) { | |
| 3827 MockHttpCache cache; | |
| 3828 cache.disk_cache()->set_fail_sparse_requests(); | |
| 3829 | |
| 3830 // Run a cacheable request to prime the cache. | |
| 3831 MockTransaction transaction(kTypicalGET_Transaction); | |
| 3832 transaction.url = kRangeGET_TransactionOK.url; | |
| 3833 AddMockTransaction(&transaction); | |
| 3834 RunTransactionTest(cache.http_cache(), transaction); | |
| 3835 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | |
| 3836 EXPECT_EQ(0, cache.disk_cache()->open_count()); | |
| 3837 EXPECT_EQ(1, cache.disk_cache()->create_count()); | |
| 3838 | |
| 3839 // Verify that we added the entry. | |
| 3840 disk_cache::Entry* entry; | |
| 3841 net::TestCompletionCallback cb; | |
| 3842 int rv = cache.disk_cache()->OpenEntry(transaction.url, | |
| 3843 &entry, | |
| 3844 cb.callback()); | |
| 3845 ASSERT_EQ(net::OK, cb.GetResult(rv)); | |
| 3846 EXPECT_EQ(1, cache.disk_cache()->open_count()); | |
| 3847 entry->Close(); | |
| 3848 RemoveMockTransaction(&transaction); | |
| 3849 | |
| 3850 // Request the range with the backend that does not support it. | |
| 3851 MockTransaction transaction2(kRangeGET_TransactionOK); | |
| 3852 std::string headers; | |
| 3853 AddMockTransaction(&transaction2); | |
| 3854 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); | |
| 3855 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | |
| 3856 EXPECT_EQ(2, cache.disk_cache()->open_count()); | |
| 3857 EXPECT_EQ(2, cache.disk_cache()->create_count()); | |
| 3858 | |
| 3859 // Mock cache would return net::ERR_CACHE_OPEN_FAILURE on a doomed entry, even | |
| 3860 // if it was re-created later, so this effectively checks that the old data is | |
| 3861 // gone. | |
| 3862 disk_cache::Entry* entry2; | |
| 3863 rv = cache.disk_cache()->OpenEntry(transaction2.url, | |
| 3864 &entry2, | |
| 3865 cb.callback()); | |
| 3866 ASSERT_EQ(net::ERR_CACHE_OPEN_FAILURE, cb.GetResult(rv)); | |
| 3867 RemoveMockTransaction(&transaction2); | |
| 3868 } | |
| 3869 | |
| 3870 TEST(HttpCache, RangeGET_SparseNotImplementedOnEmptyCache) { | |
| 3871 MockHttpCache cache; | |
| 3872 cache.disk_cache()->set_fail_sparse_requests(); | |
| 3873 | |
| 3874 // Request the range with the backend that does not support it. | |
| 3875 MockTransaction transaction(kRangeGET_TransactionOK); | |
| 3876 std::string headers; | |
| 3877 AddMockTransaction(&transaction); | |
| 3878 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | |
| 3879 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | |
| 3880 EXPECT_EQ(0, cache.disk_cache()->open_count()); | |
| 3881 EXPECT_EQ(1, cache.disk_cache()->create_count()); | |
| 3882 | |
| 3883 // Mock cache would return net::ERR_CACHE_OPEN_FAILURE on a doomed entry, even | |
| 3884 // if it was re-created later, so this effectively checks that the old data is | |
| 3885 // gone as a result of a failed range write. | |
| 3886 disk_cache::Entry* entry; | |
| 3887 net::TestCompletionCallback cb; | |
| 3888 int rv = cache.disk_cache()->OpenEntry(transaction.url, | |
| 3889 &entry, | |
| 3890 cb.callback()); | |
| 3891 ASSERT_EQ(net::ERR_CACHE_OPEN_FAILURE, cb.GetResult(rv)); | |
| 3892 RemoveMockTransaction(&transaction); | |
| 3893 } | |
| 3894 | |
| 3895 // Tests that we can cache range requests and fetch random blocks from the | 3992 // Tests that we can cache range requests and fetch random blocks from the |
| 3896 // cache and the network, with synchronous responses. | 3993 // cache and the network, with synchronous responses. |
| 3897 TEST(HttpCache, RangeGET_SyncOK) { | 3994 TEST(HttpCache, RangeGET_SyncOK) { |
| 3898 MockHttpCache cache; | 3995 MockHttpCache cache; |
| 3899 | 3996 |
| 3900 MockTransaction transaction(kRangeGET_TransactionOK); | 3997 MockTransaction transaction(kRangeGET_TransactionOK); |
| 3901 transaction.test_mode = TEST_MODE_SYNC_ALL; | 3998 transaction.test_mode = TEST_MODE_SYNC_ALL; |
| 3902 AddMockTransaction(&transaction); | 3999 AddMockTransaction(&transaction); |
| 3903 | 4000 |
| 3904 // Write to the cache (40-49). | 4001 // Write to the cache (40-49). |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4092 | 4189 |
| 4093 // And the entry should be gone. | 4190 // And the entry should be gone. |
| 4094 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); | 4191 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
| 4095 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 4192 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 4096 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4193 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4097 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 4194 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 4098 | 4195 |
| 4099 RemoveMockTransaction(&kRangeGET_TransactionOK); | 4196 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 4100 } | 4197 } |
| 4101 | 4198 |
| 4199 // Tests that when a server returns 206 with a sub-range of the requested range, |
| 4200 // and there is nothing stored in the cache, the returned response is passed to |
| 4201 // the caller as is. In this context, a subrange means a response that starts |
| 4202 // with the same byte that was requested, but that is not the whole range that |
| 4203 // was requested. |
| 4204 TEST(HttpCache, RangeGET_206ReturnsSubrangeRange_NoCachedContent) { |
| 4205 MockHttpCache cache; |
| 4206 std::string headers; |
| 4207 |
| 4208 // Request a large range (40-59). The server sends 40-49. |
| 4209 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
| 4210 transaction.request_headers = "Range: bytes = 40-59\r\n" EXTRA_HEADER; |
| 4211 transaction.response_headers = |
| 4212 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
| 4213 "ETag: \"foo\"\n" |
| 4214 "Accept-Ranges: bytes\n" |
| 4215 "Content-Length: 10\n" |
| 4216 "Content-Range: bytes 40-49/80\n"; |
| 4217 transaction.handler = nullptr; |
| 4218 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4219 |
| 4220 Verify206Response(headers, 40, 49); |
| 4221 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 4222 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 4223 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4224 } |
| 4225 |
| 4226 // Tests that when a server returns 206 with a sub-range of the requested range, |
| 4227 // and there was an entry stored in the cache, the cache gets out of the way. |
| 4228 TEST(HttpCache, RangeGET_206ReturnsSubrangeRange_CachedContent) { |
| 4229 MockHttpCache cache; |
| 4230 std::string headers; |
| 4231 |
| 4232 // Write to the cache (70-79). |
| 4233 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
| 4234 transaction.request_headers = "Range: bytes = 70-79\r\n" EXTRA_HEADER; |
| 4235 transaction.data = "rg: 70-79 "; |
| 4236 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4237 Verify206Response(headers, 70, 79); |
| 4238 |
| 4239 // Request a large range (40-79). The cache will ask the server for 40-59. |
| 4240 // The server returns 40-49. The cache should consider the server confused and |
| 4241 // abort caching, restarting the request without caching. |
| 4242 transaction.request_headers = "Range: bytes = 40-79\r\n" EXTRA_HEADER; |
| 4243 transaction.response_headers = |
| 4244 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
| 4245 "ETag: \"foo\"\n" |
| 4246 "Accept-Ranges: bytes\n" |
| 4247 "Content-Length: 10\n" |
| 4248 "Content-Range: bytes 40-49/80\n"; |
| 4249 transaction.handler = nullptr; |
| 4250 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4251 |
| 4252 // Two new network requests were issued, one from the cache and another after |
| 4253 // deleting the entry. |
| 4254 Verify206Response(headers, 40, 49); |
| 4255 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 4256 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4257 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4258 |
| 4259 // The entry was deleted. |
| 4260 RunTransactionTest(cache.http_cache(), transaction); |
| 4261 EXPECT_EQ(4, cache.network_layer()->transaction_count()); |
| 4262 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4263 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 4264 } |
| 4265 |
| 4266 // Tests that when a server returns 206 with a sub-range of the requested range, |
| 4267 // and there was an entry stored in the cache, the cache gets out of the way, |
| 4268 // when the caller is not using ranges. |
| 4269 TEST(HttpCache, GET_206ReturnsSubrangeRange_CachedContent) { |
| 4270 MockHttpCache cache; |
| 4271 std::string headers; |
| 4272 |
| 4273 // Write to the cache (70-79). |
| 4274 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
| 4275 transaction.request_headers = "Range: bytes = 70-79\r\n" EXTRA_HEADER; |
| 4276 transaction.data = "rg: 70-79 "; |
| 4277 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4278 Verify206Response(headers, 70, 79); |
| 4279 |
| 4280 // Don't ask for a range. The cache will ask the server for 0-69. |
| 4281 // The server returns 40-49. The cache should consider the server confused and |
| 4282 // abort caching, restarting the request. |
| 4283 // The second network request should not be a byte range request so the server |
| 4284 // should return 200 + "Not a range" |
| 4285 transaction.request_headers = "X-Return-Default-Range:\r\n" EXTRA_HEADER; |
| 4286 transaction.data = "Not a range"; |
| 4287 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4288 |
| 4289 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); |
| 4290 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 4291 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4292 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4293 |
| 4294 // The entry was deleted. |
| 4295 RunTransactionTest(cache.http_cache(), transaction); |
| 4296 EXPECT_EQ(4, cache.network_layer()->transaction_count()); |
| 4297 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4298 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 4299 } |
| 4300 |
| 4301 // Tests that when a server returns 206 with a random range and there is |
| 4302 // nothing stored in the cache, the returned response is passed to the caller |
| 4303 // as is. In this context, a WrongRange means that the returned range may or may |
| 4304 // not have any relationship with the requested range (may or may not be |
| 4305 // contained). The important part is that the first byte doesn't match the first |
| 4306 // requested byte. |
| 4307 TEST(HttpCache, RangeGET_206ReturnsWrongRange_NoCachedContent) { |
| 4308 MockHttpCache cache; |
| 4309 std::string headers; |
| 4310 |
| 4311 // Request a large range (30-59). The server sends (40-49). |
| 4312 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
| 4313 transaction.request_headers = "Range: bytes = 30-59\r\n" EXTRA_HEADER; |
| 4314 transaction.response_headers = |
| 4315 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
| 4316 "ETag: \"foo\"\n" |
| 4317 "Accept-Ranges: bytes\n" |
| 4318 "Content-Length: 10\n" |
| 4319 "Content-Range: bytes 40-49/80\n"; |
| 4320 transaction.handler = nullptr; |
| 4321 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4322 |
| 4323 Verify206Response(headers, 40, 49); |
| 4324 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 4325 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 4326 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4327 |
| 4328 // The entry was deleted. |
| 4329 RunTransactionTest(cache.http_cache(), transaction); |
| 4330 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 4331 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 4332 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 4333 } |
| 4334 |
| 4335 // Tests that when a server returns 206 with a random range and there is |
| 4336 // an entry stored in the cache, the cache gets out of the way. |
| 4337 TEST(HttpCache, RangeGET_206ReturnsWrongRange_CachedContent) { |
| 4338 MockHttpCache cache; |
| 4339 std::string headers; |
| 4340 |
| 4341 // Write to the cache (70-79). |
| 4342 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
| 4343 transaction.request_headers = "Range: bytes = 70-79\r\n" EXTRA_HEADER; |
| 4344 transaction.data = "rg: 70-79 "; |
| 4345 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4346 Verify206Response(headers, 70, 79); |
| 4347 |
| 4348 // Request a large range (30-79). The cache will ask the server for 30-69. |
| 4349 // The server returns 40-49. The cache should consider the server confused and |
| 4350 // abort caching, returning the weird range to the caller. |
| 4351 transaction.request_headers = "Range: bytes = 30-79\r\n" EXTRA_HEADER; |
| 4352 transaction.response_headers = |
| 4353 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
| 4354 "ETag: \"foo\"\n" |
| 4355 "Accept-Ranges: bytes\n" |
| 4356 "Content-Length: 10\n" |
| 4357 "Content-Range: bytes 40-49/80\n"; |
| 4358 transaction.handler = nullptr; |
| 4359 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4360 |
| 4361 Verify206Response(headers, 40, 49); |
| 4362 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 4363 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4364 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4365 |
| 4366 // The entry was deleted. |
| 4367 RunTransactionTest(cache.http_cache(), transaction); |
| 4368 EXPECT_EQ(4, cache.network_layer()->transaction_count()); |
| 4369 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4370 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 4371 } |
| 4372 |
| 4373 // Tests that when a caller asks for a range beyond EOF, with an empty cache, |
| 4374 // the response matches the one provided by the server. |
| 4375 TEST(HttpCache, RangeGET_206ReturnsSmallerFile_NoCachedContent) { |
| 4376 MockHttpCache cache; |
| 4377 std::string headers; |
| 4378 |
| 4379 // Request a large range (70-99). The server sends 70-79. |
| 4380 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
| 4381 transaction.request_headers = "Range: bytes = 70-99\r\n" EXTRA_HEADER; |
| 4382 transaction.data = "rg: 70-79 "; |
| 4383 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4384 |
| 4385 Verify206Response(headers, 70, 79); |
| 4386 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 4387 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 4388 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4389 |
| 4390 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
| 4391 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4392 } |
| 4393 |
| 4394 // Tests that when a caller asks for a range beyond EOF, with a cached entry, |
| 4395 // the cache automatically fixes the request. |
| 4396 TEST(HttpCache, RangeGET_206ReturnsSmallerFile_CachedContent) { |
| 4397 MockHttpCache cache; |
| 4398 std::string headers; |
| 4399 |
| 4400 // Write to the cache (40-49). |
| 4401 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
| 4402 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4403 |
| 4404 // Request a large range (70-99). The server sends 70-79. |
| 4405 transaction.request_headers = "Range: bytes = 70-99\r\n" EXTRA_HEADER; |
| 4406 transaction.data = "rg: 70-79 "; |
| 4407 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4408 |
| 4409 Verify206Response(headers, 70, 79); |
| 4410 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 4411 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4412 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4413 |
| 4414 // The entry was not deleted (the range was automatically fixed). |
| 4415 RunTransactionTest(cache.http_cache(), transaction); |
| 4416 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 4417 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
| 4418 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4419 } |
| 4420 |
| 4421 // Tests that when a caller asks for a not-satisfiable range, the server's |
| 4422 // response is forwarded to the caller. |
| 4423 TEST(HttpCache, RangeGET_416_NoCachedContent) { |
| 4424 MockHttpCache cache; |
| 4425 std::string headers; |
| 4426 |
| 4427 // Request a range beyond EOF (80-99). |
| 4428 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
| 4429 transaction.request_headers = "Range: bytes = 80-99\r\n" EXTRA_HEADER; |
| 4430 transaction.data = ""; |
| 4431 transaction.status = "HTTP/1.1 416 Requested Range Not Satisfiable"; |
| 4432 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 4433 |
| 4434 EXPECT_EQ(0U, headers.find(transaction.status)); |
| 4435 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 4436 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 4437 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4438 |
| 4439 // The entry was deleted. |
| 4440 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
| 4441 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 4442 } |
| 4443 |
| 4102 // Tests that we cache 301s for range requests. | 4444 // Tests that we cache 301s for range requests. |
| 4103 TEST(HttpCache, RangeGET_301) { | 4445 TEST(HttpCache, RangeGET_301) { |
| 4104 MockHttpCache cache; | 4446 MockHttpCache cache; |
| 4105 ScopedMockTransaction transaction(kRangeGET_TransactionOK); | 4447 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
| 4106 transaction.status = "HTTP/1.1 301 Moved Permanently"; | 4448 transaction.status = "HTTP/1.1 301 Moved Permanently"; |
| 4107 transaction.response_headers = "Location: http://www.bar.com/\n"; | 4449 transaction.response_headers = "Location: http://www.bar.com/\n"; |
| 4108 transaction.data = ""; | 4450 transaction.data = ""; |
| 4109 transaction.handler = NULL; | 4451 transaction.handler = NULL; |
| 4110 AddMockTransaction(&transaction); | |
| 4111 | 4452 |
| 4112 // Write to the cache. | 4453 // Write to the cache. |
| 4113 RunTransactionTest(cache.http_cache(), transaction); | 4454 RunTransactionTest(cache.http_cache(), transaction); |
| 4114 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4455 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 4115 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 4456 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 4116 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4457 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4117 | 4458 |
| 4118 // Read from the cache. | 4459 // Read from the cache. |
| 4119 RunTransactionTest(cache.http_cache(), transaction); | 4460 RunTransactionTest(cache.http_cache(), transaction); |
| 4120 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4461 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 4121 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4462 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4122 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4463 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4123 | |
| 4124 RemoveMockTransaction(&transaction); | |
| 4125 } | 4464 } |
| 4126 | 4465 |
| 4127 // Tests that we can cache range requests when the start or end is unknown. | 4466 // Tests that we can cache range requests when the start or end is unknown. |
| 4128 // We start with one suffix request, followed by a request from a given point. | 4467 // We start with one suffix request, followed by a request from a given point. |
| 4129 TEST(HttpCache, UnknownRangeGET_1) { | 4468 TEST(HttpCache, UnknownRangeGET_1) { |
| 4130 MockHttpCache cache; | 4469 MockHttpCache cache; |
| 4131 AddMockTransaction(&kRangeGET_TransactionOK); | 4470 AddMockTransaction(&kRangeGET_TransactionOK); |
| 4132 std::string headers; | 4471 std::string headers; |
| 4133 | 4472 |
| 4134 // Write to the cache (70-79). | 4473 // Write to the cache (70-79). |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4241 | 4580 |
| 4242 Verify206Response(headers, 40, 49); | 4581 Verify206Response(headers, 40, 49); |
| 4243 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4582 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 4244 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 4583 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 4245 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4584 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4246 TestLoadTimingNetworkRequest(load_timing_info); | 4585 TestLoadTimingNetworkRequest(load_timing_info); |
| 4247 | 4586 |
| 4248 // Write and read from the cache (0-79), when not asked for a range. | 4587 // Write and read from the cache (0-79), when not asked for a range. |
| 4249 MockTransaction transaction(kRangeGET_TransactionOK); | 4588 MockTransaction transaction(kRangeGET_TransactionOK); |
| 4250 transaction.request_headers = EXTRA_HEADER; | 4589 transaction.request_headers = EXTRA_HEADER; |
| 4251 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 4590 transaction.data = kFullRangeData; |
| 4252 "rg: 50-59 rg: 60-69 rg: 70-79 "; | |
| 4253 RunTransactionTestWithResponseAndGetTiming( | 4591 RunTransactionTestWithResponseAndGetTiming( |
| 4254 cache.http_cache(), transaction, &headers, log.bound(), | 4592 cache.http_cache(), transaction, &headers, log.bound(), |
| 4255 &load_timing_info); | 4593 &load_timing_info); |
| 4256 | 4594 |
| 4257 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); | 4595 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); |
| 4258 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 4596 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 4259 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4597 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4260 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4598 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4261 TestLoadTimingNetworkRequest(load_timing_info); | 4599 TestLoadTimingNetworkRequest(load_timing_info); |
| 4262 | 4600 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 4292 Verify206Response(headers, 70, 79); | 4630 Verify206Response(headers, 70, 79); |
| 4293 | 4631 |
| 4294 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 4632 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 4295 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 4633 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4296 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4634 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4297 TestLoadTimingNetworkRequest(load_timing_info); | 4635 TestLoadTimingNetworkRequest(load_timing_info); |
| 4298 | 4636 |
| 4299 // Read from the cache (0-9), write and read from cache (10 - 79). | 4637 // Read from the cache (0-9), write and read from cache (10 - 79). |
| 4300 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; | 4638 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; |
| 4301 transaction.request_headers = "Foo: bar\r\n" EXTRA_HEADER; | 4639 transaction.request_headers = "Foo: bar\r\n" EXTRA_HEADER; |
| 4302 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 4640 transaction.data = kFullRangeData; |
| 4303 "rg: 50-59 rg: 60-69 rg: 70-79 "; | |
| 4304 RunTransactionTestWithResponseAndGetTiming( | 4641 RunTransactionTestWithResponseAndGetTiming( |
| 4305 cache.http_cache(), transaction, &headers, log.bound(), | 4642 cache.http_cache(), transaction, &headers, log.bound(), |
| 4306 &load_timing_info); | 4643 &load_timing_info); |
| 4307 | 4644 |
| 4308 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); | 4645 EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); |
| 4309 EXPECT_EQ(4, cache.network_layer()->transaction_count()); | 4646 EXPECT_EQ(4, cache.network_layer()->transaction_count()); |
| 4310 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 4647 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
| 4311 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4648 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4312 TestLoadTimingNetworkRequest(load_timing_info); | 4649 TestLoadTimingNetworkRequest(load_timing_info); |
| 4313 | 4650 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4493 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 4830 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 4494 } | 4831 } |
| 4495 | 4832 |
| 4496 // Tests that we can handle range requests with cached 200 responses. | 4833 // Tests that we can handle range requests with cached 200 responses. |
| 4497 TEST(HttpCache, RangeGET_Previous200) { | 4834 TEST(HttpCache, RangeGET_Previous200) { |
| 4498 MockHttpCache cache; | 4835 MockHttpCache cache; |
| 4499 | 4836 |
| 4500 // Store the whole thing with status 200. | 4837 // Store the whole thing with status 200. |
| 4501 MockTransaction transaction(kTypicalGET_Transaction); | 4838 MockTransaction transaction(kTypicalGET_Transaction); |
| 4502 transaction.url = kRangeGET_TransactionOK.url; | 4839 transaction.url = kRangeGET_TransactionOK.url; |
| 4503 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 4840 transaction.data = kFullRangeData; |
| 4504 "rg: 50-59 rg: 60-69 rg: 70-79 "; | |
| 4505 AddMockTransaction(&transaction); | 4841 AddMockTransaction(&transaction); |
| 4506 RunTransactionTest(cache.http_cache(), transaction); | 4842 RunTransactionTest(cache.http_cache(), transaction); |
| 4507 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 4843 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 4508 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 4844 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 4509 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4845 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4510 | 4846 |
| 4511 RemoveMockTransaction(&transaction); | 4847 RemoveMockTransaction(&transaction); |
| 4512 AddMockTransaction(&kRangeGET_TransactionOK); | 4848 AddMockTransaction(&kRangeGET_TransactionOK); |
| 4513 | 4849 |
| 4514 // Now see that we use the stored entry. | 4850 // Now see that we use the stored entry. |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4827 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5163 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4828 | 5164 |
| 4829 // Verify that we don't have a cached entry. | 5165 // Verify that we don't have a cached entry. |
| 4830 disk_cache::Entry* entry; | 5166 disk_cache::Entry* entry; |
| 4831 EXPECT_FALSE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry)); | 5167 EXPECT_FALSE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry)); |
| 4832 | 5168 |
| 4833 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5169 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 4834 } | 5170 } |
| 4835 | 5171 |
| 4836 // Tests that if a server tells us conflicting information about a resource we | 5172 // Tests that if a server tells us conflicting information about a resource we |
| 4837 // ignore the response. | 5173 // drop the entry. |
| 4838 TEST(HttpCache, RangeGET_InvalidResponse3) { | 5174 TEST(HttpCache, RangeGET_InvalidResponse3) { |
| 4839 MockHttpCache cache; | 5175 MockHttpCache cache; |
| 4840 std::string headers; | 5176 std::string headers; |
| 4841 | 5177 |
| 4842 MockTransaction transaction(kRangeGET_TransactionOK); | 5178 MockTransaction transaction(kRangeGET_TransactionOK); |
| 4843 transaction.handler = NULL; | 5179 transaction.handler = NULL; |
| 4844 transaction.request_headers = "Range: bytes = 50-59\r\n" EXTRA_HEADER; | 5180 transaction.request_headers = "Range: bytes = 50-59\r\n" EXTRA_HEADER; |
| 4845 std::string response_headers(transaction.response_headers); | 5181 std::string response_headers(transaction.response_headers); |
| 4846 response_headers.append("Content-Range: bytes 50-59/160\n"); | 5182 response_headers.append("Content-Range: bytes 50-59/160\n"); |
| 4847 transaction.response_headers = response_headers.c_str(); | 5183 transaction.response_headers = response_headers.c_str(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4859 // This transaction will report a resource size of 80 bytes, and we think it's | 5195 // This transaction will report a resource size of 80 bytes, and we think it's |
| 4860 // 160 so we should ignore the response. | 5196 // 160 so we should ignore the response. |
| 4861 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 5197 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 4862 &headers); | 5198 &headers); |
| 4863 | 5199 |
| 4864 Verify206Response(headers, 40, 49); | 5200 Verify206Response(headers, 40, 49); |
| 4865 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 5201 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 4866 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 5202 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4867 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5203 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4868 | 5204 |
| 4869 // Verify that we cached the first response but not the second one. | 5205 // Verify that the entry is gone. |
| 4870 disk_cache::Entry* en; | 5206 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
| 4871 ASSERT_TRUE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &en)); | 5207 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4872 | 5208 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 4873 int64 cached_start = 0; | |
| 4874 net::TestCompletionCallback cb; | |
| 4875 int rv = en->GetAvailableRange(40, 20, &cached_start, cb.callback()); | |
| 4876 EXPECT_EQ(10, cb.GetResult(rv)); | |
| 4877 EXPECT_EQ(50, cached_start); | |
| 4878 en->Close(); | |
| 4879 | |
| 4880 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5209 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 4881 } | 5210 } |
| 4882 | 5211 |
| 4883 // Tests that we handle large range values properly. | 5212 // Tests that we handle large range values properly. |
| 4884 TEST(HttpCache, RangeGET_LargeValues) { | 5213 TEST(HttpCache, RangeGET_LargeValues) { |
| 4885 // We need a real sparse cache for this test. | 5214 // We need a real sparse cache for this test. |
| 4886 MockHttpCache cache(net::HttpCache::DefaultBackend::InMemory(1024 * 1024)); | 5215 MockHttpCache cache(net::HttpCache::DefaultBackend::InMemory(1024 * 1024)); |
| 4887 std::string headers; | 5216 std::string headers; |
| 4888 | 5217 |
| 4889 MockTransaction transaction(kRangeGET_TransactionOK); | 5218 MockTransaction transaction(kRangeGET_TransactionOK); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4947 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 5276 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 4948 | 5277 |
| 4949 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5278 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 4950 } | 5279 } |
| 4951 | 5280 |
| 4952 // Tests that we don't crash when after reading from the cache we issue a | 5281 // Tests that we don't crash when after reading from the cache we issue a |
| 4953 // request for the next range and the server gives us a 200 synchronously. | 5282 // request for the next range and the server gives us a 200 synchronously. |
| 4954 TEST(HttpCache, RangeGET_FastFlakyServer) { | 5283 TEST(HttpCache, RangeGET_FastFlakyServer) { |
| 4955 MockHttpCache cache; | 5284 MockHttpCache cache; |
| 4956 | 5285 |
| 4957 MockTransaction transaction(kRangeGET_TransactionOK); | 5286 ScopedMockTransaction transaction(kRangeGET_TransactionOK); |
| 4958 transaction.request_headers = "Range: bytes = 40-\r\n" EXTRA_HEADER; | 5287 transaction.request_headers = "Range: bytes = 40-\r\n" EXTRA_HEADER; |
| 4959 transaction.test_mode = TEST_MODE_SYNC_NET_START; | 5288 transaction.test_mode = TEST_MODE_SYNC_NET_START; |
| 4960 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; | 5289 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; |
| 4961 AddMockTransaction(&transaction); | |
| 4962 | 5290 |
| 4963 // Write to the cache. | 5291 // Write to the cache. |
| 4964 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); | 5292 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
| 4965 | 5293 |
| 4966 // And now read from the cache and the network. | 5294 // And now read from the cache and the network. |
| 4967 RangeTransactionServer handler; | 5295 RangeTransactionServer handler; |
| 4968 handler.set_bad_200(true); | 5296 handler.set_bad_200(true); |
| 4969 transaction.data = "Not a range"; | 5297 transaction.data = "Not a range"; |
| 4970 RunTransactionTest(cache.http_cache(), transaction); | 5298 net::CapturingBoundNetLog log; |
| 5299 RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound()); |
| 4971 | 5300 |
| 4972 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 5301 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 4973 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 5302 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 4974 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5303 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4975 | 5304 EXPECT_TRUE(LogContainsEventType( |
| 4976 RemoveMockTransaction(&transaction); | 5305 log, net::NetLog::TYPE_HTTP_CACHE_RE_SEND_PARTIAL_REQUEST)); |
| 4977 } | 5306 } |
| 4978 | 5307 |
| 4979 // Tests that when the server gives us less data than expected, we don't keep | 5308 // Tests that when the server gives us less data than expected, we don't keep |
| 4980 // asking for more data. | 5309 // asking for more data. |
| 4981 TEST(HttpCache, RangeGET_FastFlakyServer2) { | 5310 TEST(HttpCache, RangeGET_FastFlakyServer2) { |
| 4982 MockHttpCache cache; | 5311 MockHttpCache cache; |
| 4983 | 5312 |
| 4984 // First, check with an empty cache (WRITE mode). | 5313 // First, check with an empty cache (WRITE mode). |
| 4985 MockTransaction transaction(kRangeGET_TransactionOK); | 5314 MockTransaction transaction(kRangeGET_TransactionOK); |
| 4986 transaction.request_headers = "Range: bytes = 40-49\r\n" EXTRA_HEADER; | 5315 transaction.request_headers = "Range: bytes = 40-49\r\n" EXTRA_HEADER; |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5327 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 5656 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
| 5328 "ETag: \"foo\"\n" | 5657 "ETag: \"foo\"\n" |
| 5329 "Accept-Ranges: bytes\n" | 5658 "Accept-Ranges: bytes\n" |
| 5330 "Content-Length: 80\n"); | 5659 "Content-Length: 80\n"); |
| 5331 CreateTruncatedEntry(raw_headers, &cache); | 5660 CreateTruncatedEntry(raw_headers, &cache); |
| 5332 | 5661 |
| 5333 // Now make a regular request. | 5662 // Now make a regular request. |
| 5334 std::string headers; | 5663 std::string headers; |
| 5335 MockTransaction transaction(kRangeGET_TransactionOK); | 5664 MockTransaction transaction(kRangeGET_TransactionOK); |
| 5336 transaction.request_headers = EXTRA_HEADER; | 5665 transaction.request_headers = EXTRA_HEADER; |
| 5337 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 5666 transaction.data = kFullRangeData; |
| 5338 "rg: 50-59 rg: 60-69 rg: 70-79 "; | |
| 5339 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 5667 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 5340 | 5668 |
| 5341 // We update the headers with the ones received while revalidating. | 5669 // We update the headers with the ones received while revalidating. |
| 5342 std::string expected_headers( | 5670 std::string expected_headers( |
| 5343 "HTTP/1.1 200 OK\n" | 5671 "HTTP/1.1 200 OK\n" |
| 5344 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 5672 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
| 5345 "Accept-Ranges: bytes\n" | 5673 "Accept-Ranges: bytes\n" |
| 5346 "ETag: \"foo\"\n" | 5674 "ETag: \"foo\"\n" |
| 5347 "Content-Length: 80\n"); | 5675 "Content-Length: 80\n"); |
| 5348 | 5676 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 5376 "Content-Length: 80\n"); | 5704 "Content-Length: 80\n"); |
| 5377 CreateTruncatedEntry(raw_headers, &cache); | 5705 CreateTruncatedEntry(raw_headers, &cache); |
| 5378 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5706 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 5379 | 5707 |
| 5380 // Now make a regular request. | 5708 // Now make a regular request. |
| 5381 MockTransaction transaction(kRangeGET_TransactionOK); | 5709 MockTransaction transaction(kRangeGET_TransactionOK); |
| 5382 transaction.request_headers = EXTRA_HEADER; | 5710 transaction.request_headers = EXTRA_HEADER; |
| 5383 std::string response_headers(transaction.response_headers); | 5711 std::string response_headers(transaction.response_headers); |
| 5384 response_headers += ("Cache-Control: no-store\n"); | 5712 response_headers += ("Cache-Control: no-store\n"); |
| 5385 transaction.response_headers = response_headers.c_str(); | 5713 transaction.response_headers = response_headers.c_str(); |
| 5386 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 5714 transaction.data = kFullRangeData; |
| 5387 "rg: 50-59 rg: 60-69 rg: 70-79 "; | |
| 5388 AddMockTransaction(&transaction); | 5715 AddMockTransaction(&transaction); |
| 5389 | 5716 |
| 5390 std::string headers; | 5717 std::string headers; |
| 5391 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 5718 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 5392 | 5719 |
| 5393 // We update the headers with the ones received while revalidating. | 5720 // We update the headers with the ones received while revalidating. |
| 5394 std::string expected_headers( | 5721 std::string expected_headers( |
| 5395 "HTTP/1.1 200 OK\n" | 5722 "HTTP/1.1 200 OK\n" |
| 5396 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 5723 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
| 5397 "Accept-Ranges: bytes\n" | 5724 "Accept-Ranges: bytes\n" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 5422 "Content-Length: 80\n"); | 5749 "Content-Length: 80\n"); |
| 5423 CreateTruncatedEntry(raw_headers, &cache); | 5750 CreateTruncatedEntry(raw_headers, &cache); |
| 5424 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5751 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 5425 | 5752 |
| 5426 // Now make a regular request. | 5753 // Now make a regular request. |
| 5427 MockTransaction transaction(kRangeGET_TransactionOK); | 5754 MockTransaction transaction(kRangeGET_TransactionOK); |
| 5428 transaction.request_headers = EXTRA_HEADER; | 5755 transaction.request_headers = EXTRA_HEADER; |
| 5429 std::string response_headers(transaction.response_headers); | 5756 std::string response_headers(transaction.response_headers); |
| 5430 response_headers += ("Cache-Control: no-store\n"); | 5757 response_headers += ("Cache-Control: no-store\n"); |
| 5431 transaction.response_headers = response_headers.c_str(); | 5758 transaction.response_headers = response_headers.c_str(); |
| 5432 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 5759 transaction.data = kFullRangeData; |
| 5433 "rg: 50-59 rg: 60-69 rg: 70-79 "; | |
| 5434 AddMockTransaction(&transaction); | 5760 AddMockTransaction(&transaction); |
| 5435 | 5761 |
| 5436 MockHttpRequest request(transaction); | 5762 MockHttpRequest request(transaction); |
| 5437 Context* c = new Context(); | 5763 Context* c = new Context(); |
| 5438 | 5764 |
| 5439 int rv = cache.CreateTransaction(&c->trans); | 5765 int rv = cache.CreateTransaction(&c->trans); |
| 5440 ASSERT_EQ(net::OK, rv); | 5766 ASSERT_EQ(net::OK, rv); |
| 5441 | 5767 |
| 5442 // Queue another request to this transaction. We have to start this request | 5768 // Queue another request to this transaction. We have to start this request |
| 5443 // before the first one gets the response from the server and dooms the entry, | 5769 // before the first one gets the response from the server and dooms the entry, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5517 "ETag: \"foo\"\n" | 5843 "ETag: \"foo\"\n" |
| 5518 "Cache-Control: max-age= 36000\n" | 5844 "Cache-Control: max-age= 36000\n" |
| 5519 "Accept-Ranges: bytes\n" | 5845 "Accept-Ranges: bytes\n" |
| 5520 "Content-Length: 80\n"); | 5846 "Content-Length: 80\n"); |
| 5521 CreateTruncatedEntry(raw_headers, &cache); | 5847 CreateTruncatedEntry(raw_headers, &cache); |
| 5522 | 5848 |
| 5523 // Now make a regular request. | 5849 // Now make a regular request. |
| 5524 std::string headers; | 5850 std::string headers; |
| 5525 MockTransaction transaction(kRangeGET_TransactionOK); | 5851 MockTransaction transaction(kRangeGET_TransactionOK); |
| 5526 transaction.request_headers = EXTRA_HEADER; | 5852 transaction.request_headers = EXTRA_HEADER; |
| 5527 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 5853 transaction.data = kFullRangeData; |
| 5528 "rg: 50-59 rg: 60-69 rg: 70-79 "; | |
| 5529 | 5854 |
| 5530 scoped_ptr<Context> c(new Context); | 5855 scoped_ptr<Context> c(new Context); |
| 5531 int rv = cache.CreateTransaction(&c->trans); | 5856 int rv = cache.CreateTransaction(&c->trans); |
| 5532 ASSERT_EQ(net::OK, rv); | 5857 ASSERT_EQ(net::OK, rv); |
| 5533 | 5858 |
| 5534 MockHttpRequest request(transaction); | 5859 MockHttpRequest request(transaction); |
| 5535 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 5860 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
| 5536 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); | 5861 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); |
| 5537 | 5862 |
| 5538 // We should have checked with the server before finishing Start(). | 5863 // We should have checked with the server before finishing Start(). |
| (...skipping 13 matching lines...) Expand all Loading... |
| 5552 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 5877 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
| 5553 "ETag: \"foo\"\n" | 5878 "ETag: \"foo\"\n" |
| 5554 "Accept-Ranges: bytes\n" | 5879 "Accept-Ranges: bytes\n" |
| 5555 "Content-Length: 80\n"); | 5880 "Content-Length: 80\n"); |
| 5556 CreateTruncatedEntry(raw_headers, &cache); | 5881 CreateTruncatedEntry(raw_headers, &cache); |
| 5557 | 5882 |
| 5558 // Now make a regular request. | 5883 // Now make a regular request. |
| 5559 MockTransaction transaction(kRangeGET_TransactionOK); | 5884 MockTransaction transaction(kRangeGET_TransactionOK); |
| 5560 transaction.request_headers = "X-Require-Mock-Auth: dummy\r\n" | 5885 transaction.request_headers = "X-Require-Mock-Auth: dummy\r\n" |
| 5561 EXTRA_HEADER; | 5886 EXTRA_HEADER; |
| 5562 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 5887 transaction.data = kFullRangeData; |
| 5563 "rg: 50-59 rg: 60-69 rg: 70-79 "; | |
| 5564 RangeTransactionServer handler; | 5888 RangeTransactionServer handler; |
| 5565 | 5889 |
| 5566 scoped_ptr<Context> c(new Context); | 5890 scoped_ptr<Context> c(new Context); |
| 5567 int rv = cache.CreateTransaction(&c->trans); | 5891 int rv = cache.CreateTransaction(&c->trans); |
| 5568 ASSERT_EQ(net::OK, rv); | 5892 ASSERT_EQ(net::OK, rv); |
| 5569 | 5893 |
| 5570 MockHttpRequest request(transaction); | 5894 MockHttpRequest request(transaction); |
| 5571 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); | 5895 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); |
| 5572 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); | 5896 EXPECT_EQ(net::OK, c->callback.GetResult(rv)); |
| 5573 | 5897 |
| (...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6643 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 6967 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
| 6644 "ETag: \"foo\"\n" | 6968 "ETag: \"foo\"\n" |
| 6645 "Accept-Ranges: bytes\n" | 6969 "Accept-Ranges: bytes\n" |
| 6646 "Content-Length: 80\n"); | 6970 "Content-Length: 80\n"); |
| 6647 CreateTruncatedEntry(raw_headers, &cache); | 6971 CreateTruncatedEntry(raw_headers, &cache); |
| 6648 | 6972 |
| 6649 // Now make a regular request. | 6973 // Now make a regular request. |
| 6650 std::string headers; | 6974 std::string headers; |
| 6651 MockTransaction transaction(kRangeGET_TransactionOK); | 6975 MockTransaction transaction(kRangeGET_TransactionOK); |
| 6652 transaction.request_headers = EXTRA_HEADER; | 6976 transaction.request_headers = EXTRA_HEADER; |
| 6653 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 6977 transaction.data = kFullRangeData; |
| 6654 "rg: 50-59 rg: 60-69 rg: 70-79 "; | |
| 6655 | 6978 |
| 6656 scoped_ptr<net::HttpTransaction> trans; | 6979 scoped_ptr<net::HttpTransaction> trans; |
| 6657 ASSERT_EQ(net::OK, | 6980 ASSERT_EQ(net::OK, |
| 6658 cache.http_cache()->CreateTransaction(net::MEDIUM, &trans)); | 6981 cache.http_cache()->CreateTransaction(net::MEDIUM, &trans)); |
| 6659 EXPECT_EQ(net::DEFAULT_PRIORITY, | 6982 EXPECT_EQ(net::DEFAULT_PRIORITY, |
| 6660 cache.network_layer()->last_create_transaction_priority()); | 6983 cache.network_layer()->last_create_transaction_priority()); |
| 6661 | 6984 |
| 6662 MockHttpRequest info(transaction); | 6985 MockHttpRequest info(transaction); |
| 6663 net::TestCompletionCallback callback; | 6986 net::TestCompletionCallback callback; |
| 6664 EXPECT_EQ(net::ERR_IO_PENDING, | 6987 EXPECT_EQ(net::ERR_IO_PENDING, |
| (...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7341 | 7664 |
| 7342 // Here the second transaction proceeds without reading the first body. | 7665 // Here the second transaction proceeds without reading the first body. |
| 7343 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); | 7666 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); |
| 7344 base::MessageLoop::current()->RunUntilIdle(); | 7667 base::MessageLoop::current()->RunUntilIdle(); |
| 7345 EXPECT_EQ(net::LOAD_STATE_IDLE, second->trans->GetLoadState()); | 7668 EXPECT_EQ(net::LOAD_STATE_IDLE, second->trans->GetLoadState()); |
| 7346 ASSERT_TRUE(second->trans->GetResponseInfo()); | 7669 ASSERT_TRUE(second->trans->GetResponseInfo()); |
| 7347 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( | 7670 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( |
| 7348 "Cache-Control", "no-store")); | 7671 "Cache-Control", "no-store")); |
| 7349 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction); | 7672 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction); |
| 7350 } | 7673 } |
| OLD | NEW |