OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/appcache/appcache_url_request_job.h" | 5 #include "content/browser/appcache/appcache_url_request_job.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 // 2. Use net::URLRequest to retrieve it. | 602 // 2. Use net::URLRequest to retrieve it. |
603 // 3. Verify we received what we expected to receive. | 603 // 3. Verify we received what we expected to receive. |
604 | 604 |
605 PushNextTask(base::Bind( | 605 PushNextTask(base::Bind( |
606 &AppCacheURLRequestJobTest::VerifyDeliverSmallAppCachedResponse, | 606 &AppCacheURLRequestJobTest::VerifyDeliverSmallAppCachedResponse, |
607 base::Unretained(this))); | 607 base::Unretained(this))); |
608 PushNextTask( | 608 PushNextTask( |
609 base::Bind(&AppCacheURLRequestJobTest::RequestAppCachedResource, | 609 base::Bind(&AppCacheURLRequestJobTest::RequestAppCachedResource, |
610 base::Unretained(this), false)); | 610 base::Unretained(this), false)); |
611 | 611 |
612 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); | 612 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); |
613 written_response_id_ = writer_->response_id(); | 613 written_response_id_ = writer_->response_id(); |
614 WriteBasicResponse(); | 614 WriteBasicResponse(); |
615 // Continues async | 615 // Continues async |
616 } | 616 } |
617 | 617 |
618 void RequestAppCachedResource(bool start_after_delivery_orders) { | 618 void RequestAppCachedResource(bool start_after_delivery_orders) { |
619 AppCacheStorage* storage = service_->storage(); | 619 AppCacheStorage* storage = service_->storage(); |
620 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 620 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
621 net::DEFAULT_PRIORITY, | 621 net::DEFAULT_PRIORITY, |
622 url_request_delegate_.get()); | 622 url_request_delegate_.get()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 // 2. Use net::URLRequest to retrieve it. | 676 // 2. Use net::URLRequest to retrieve it. |
677 // 3. Verify we received what we expected to receive. | 677 // 3. Verify we received what we expected to receive. |
678 | 678 |
679 PushNextTask(base::Bind( | 679 PushNextTask(base::Bind( |
680 &AppCacheURLRequestJobTest::VerifyDeliverLargeAppCachedResponse, | 680 &AppCacheURLRequestJobTest::VerifyDeliverLargeAppCachedResponse, |
681 base::Unretained(this))); | 681 base::Unretained(this))); |
682 PushNextTask(base::Bind( | 682 PushNextTask(base::Bind( |
683 &AppCacheURLRequestJobTest::RequestAppCachedResource, | 683 &AppCacheURLRequestJobTest::RequestAppCachedResource, |
684 base::Unretained(this), true)); | 684 base::Unretained(this), true)); |
685 | 685 |
686 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); | 686 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); |
687 written_response_id_ = writer_->response_id(); | 687 written_response_id_ = writer_->response_id(); |
688 WriteLargeResponse(); | 688 WriteLargeResponse(); |
689 // Continues async | 689 // Continues async |
690 } | 690 } |
691 | 691 |
692 void WriteLargeResponse() { | 692 void WriteLargeResponse() { |
693 // 3, 1k blocks | 693 // 3, 1k blocks |
694 static const char kHttpHeaders[] = | 694 static const char kHttpHeaders[] = |
695 "HTTP/1.0 200 OK\0Content-Length: 3072\0\0"; | 695 "HTTP/1.0 200 OK\0Content-Length: 3072\0\0"; |
696 scoped_refptr<IOBuffer> body(new IOBuffer(kBlockSize * 3)); | 696 scoped_refptr<IOBuffer> body(new IOBuffer(kBlockSize * 3)); |
(...skipping 22 matching lines...) Expand all Loading... |
719 void DeliverPartialResponse() { | 719 void DeliverPartialResponse() { |
720 // This test has several async steps. | 720 // This test has several async steps. |
721 // 1. Write a small response to response storage. | 721 // 1. Write a small response to response storage. |
722 // 2. Use net::URLRequest to retrieve it a subset using a range request | 722 // 2. Use net::URLRequest to retrieve it a subset using a range request |
723 // 3. Verify we received what we expected to receive. | 723 // 3. Verify we received what we expected to receive. |
724 PushNextTask(base::Bind( | 724 PushNextTask(base::Bind( |
725 &AppCacheURLRequestJobTest::VerifyDeliverPartialResponse, | 725 &AppCacheURLRequestJobTest::VerifyDeliverPartialResponse, |
726 base::Unretained(this))); | 726 base::Unretained(this))); |
727 PushNextTask(base::Bind( | 727 PushNextTask(base::Bind( |
728 &AppCacheURLRequestJobTest::MakeRangeRequest, base::Unretained(this))); | 728 &AppCacheURLRequestJobTest::MakeRangeRequest, base::Unretained(this))); |
729 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); | 729 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); |
730 written_response_id_ = writer_->response_id(); | 730 written_response_id_ = writer_->response_id(); |
731 WriteBasicResponse(); | 731 WriteBasicResponse(); |
732 // Continues async | 732 // Continues async |
733 } | 733 } |
734 | 734 |
735 void MakeRangeRequest() { | 735 void MakeRangeRequest() { |
736 AppCacheStorage* storage = service_->storage(); | 736 AppCacheStorage* storage = service_->storage(); |
737 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 737 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
738 net::DEFAULT_PRIORITY, | 738 net::DEFAULT_PRIORITY, |
739 url_request_delegate_.get()); | 739 url_request_delegate_.get()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 // 1. Write a large response to response storage. | 787 // 1. Write a large response to response storage. |
788 // 2. Use net::URLRequest to retrieve it. | 788 // 2. Use net::URLRequest to retrieve it. |
789 // 3. Cancel the request after data starts coming in. | 789 // 3. Cancel the request after data starts coming in. |
790 | 790 |
791 PushNextTask(base::Bind( | 791 PushNextTask(base::Bind( |
792 &AppCacheURLRequestJobTest::VerifyCancel, base::Unretained(this))); | 792 &AppCacheURLRequestJobTest::VerifyCancel, base::Unretained(this))); |
793 PushNextTask(base::Bind( | 793 PushNextTask(base::Bind( |
794 &AppCacheURLRequestJobTest::RequestAppCachedResource, | 794 &AppCacheURLRequestJobTest::RequestAppCachedResource, |
795 base::Unretained(this), true)); | 795 base::Unretained(this), true)); |
796 | 796 |
797 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); | 797 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); |
798 written_response_id_ = writer_->response_id(); | 798 written_response_id_ = writer_->response_id(); |
799 WriteLargeResponse(); | 799 WriteLargeResponse(); |
800 | 800 |
801 url_request_delegate_->kill_after_amount_received_ = kBlockSize; | 801 url_request_delegate_->kill_after_amount_received_ = kBlockSize; |
802 url_request_delegate_->kill_with_io_pending_ = false; | 802 url_request_delegate_->kill_with_io_pending_ = false; |
803 // Continues async | 803 // Continues async |
804 } | 804 } |
805 | 805 |
806 void VerifyCancel() { | 806 void VerifyCancel() { |
807 EXPECT_EQ(net::URLRequestStatus::CANCELED, | 807 EXPECT_EQ(net::URLRequestStatus::CANCELED, |
808 request_->status().status()); | 808 request_->status().status()); |
809 TestFinished(); | 809 TestFinished(); |
810 } | 810 } |
811 | 811 |
812 // CancelRequestWithIOPending -------------------------------------- | 812 // CancelRequestWithIOPending -------------------------------------- |
813 | 813 |
814 void CancelRequestWithIOPending() { | 814 void CancelRequestWithIOPending() { |
815 // This test has several async steps. | 815 // This test has several async steps. |
816 // 1. Write a large response to response storage. | 816 // 1. Write a large response to response storage. |
817 // 2. Use net::URLRequest to retrieve it. | 817 // 2. Use net::URLRequest to retrieve it. |
818 // 3. Cancel the request after data starts coming in. | 818 // 3. Cancel the request after data starts coming in. |
819 | 819 |
820 PushNextTask(base::Bind( | 820 PushNextTask(base::Bind( |
821 &AppCacheURLRequestJobTest::VerifyCancel, base::Unretained(this))); | 821 &AppCacheURLRequestJobTest::VerifyCancel, base::Unretained(this))); |
822 PushNextTask(base::Bind( | 822 PushNextTask(base::Bind( |
823 &AppCacheURLRequestJobTest::RequestAppCachedResource, | 823 &AppCacheURLRequestJobTest::RequestAppCachedResource, |
824 base::Unretained(this), true)); | 824 base::Unretained(this), true)); |
825 | 825 |
826 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); | 826 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); |
827 written_response_id_ = writer_->response_id(); | 827 written_response_id_ = writer_->response_id(); |
828 WriteLargeResponse(); | 828 WriteLargeResponse(); |
829 | 829 |
830 url_request_delegate_->kill_after_amount_received_ = kBlockSize; | 830 url_request_delegate_->kill_after_amount_received_ = kBlockSize; |
831 url_request_delegate_->kill_with_io_pending_ = true; | 831 url_request_delegate_->kill_with_io_pending_ = true; |
832 // Continues async | 832 // Continues async |
833 } | 833 } |
834 | 834 |
835 | 835 |
836 // Data members -------------------------------------------------------- | 836 // Data members -------------------------------------------------------- |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 | 896 |
897 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { | 897 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { |
898 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); | 898 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); |
899 } | 899 } |
900 | 900 |
901 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { | 901 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { |
902 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); | 902 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); |
903 } | 903 } |
904 | 904 |
905 } // namespace content | 905 } // namespace content |
OLD | NEW |