| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" | 
| 6 #include "base/pickle.h" | 6 #include "base/pickle.h" | 
| 7 #include "base/thread.h" | 7 #include "base/thread.h" | 
| 8 #include "base/waitable_event.h" | 8 #include "base/waitable_event.h" | 
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" | 
| 10 #include "net/url_request/url_request.h" | 10 #include "net/url_request/url_request.h" | 
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 610     EXPECT_TRUE(CompareHttpResponseInfos( | 610     EXPECT_TRUE(CompareHttpResponseInfos( | 
| 611         write_info_buffer_->http_info.get(), | 611         write_info_buffer_->http_info.get(), | 
| 612         &url_request_delegate_->received_info_)); | 612         &url_request_delegate_->received_info_)); | 
| 613     EXPECT_EQ(3072, url_request_delegate_->amount_received_); | 613     EXPECT_EQ(3072, url_request_delegate_->amount_received_); | 
| 614     char* p = url_request_delegate_->received_data_->data(); | 614     char* p = url_request_delegate_->received_data_->data(); | 
| 615     for (int i = 0; i < 3; ++i, p += kBlockSize) | 615     for (int i = 0; i < 3; ++i, p += kBlockSize) | 
| 616       EXPECT_TRUE(CheckData(i + 1, p, kBlockSize)); | 616       EXPECT_TRUE(CheckData(i + 1, p, kBlockSize)); | 
| 617     TestFinished(); | 617     TestFinished(); | 
| 618   } | 618   } | 
| 619 | 619 | 
|  | 620   // DeliverPartialResponse -------------------------------------- | 
|  | 621 | 
|  | 622   void DeliverPartialResponse() { | 
|  | 623     // This test has several async steps. | 
|  | 624     // 1. Write a small response to response storage. | 
|  | 625     // 2. Use URLRequest to retrieve it a subset using a range request | 
|  | 626     // 3. Verify we received what we expected to receive. | 
|  | 627     PushNextTask(NewRunnableMethod( | 
|  | 628        this, &AppCacheURLRequestJobTest::VerifyDeliverPartialResponse)); | 
|  | 629     PushNextTask(NewRunnableMethod( | 
|  | 630        this, &AppCacheURLRequestJobTest::MakeRangeRequest)); | 
|  | 631     writer_.reset(service_->storage()->CreateResponseWriter(GURL())); | 
|  | 632     written_response_id_ = writer_->response_id(); | 
|  | 633     WriteBasicResponse(); | 
|  | 634     // Continues async | 
|  | 635   } | 
|  | 636 | 
|  | 637   void MakeRangeRequest() { | 
|  | 638     AppCacheStorage* storage = service_->storage(); | 
|  | 639     request_.reset( | 
|  | 640         new URLRequest(GURL("http://blah/"), url_request_delegate_.get())); | 
|  | 641 | 
|  | 642     // Request a range, the 3 middle chars out of 'Hello' | 
|  | 643     net::HttpRequestHeaders extra_headers; | 
|  | 644     extra_headers.SetHeader("Range", "bytes= 1-3"); | 
|  | 645     request_->SetExtraRequestHeaders(extra_headers); | 
|  | 646 | 
|  | 647     // Create job with orders to deliver an appcached entry. | 
|  | 648     scoped_refptr<AppCacheURLRequestJob> job( | 
|  | 649         new AppCacheURLRequestJob(request_.get(), storage)); | 
|  | 650     job->DeliverAppCachedResponse( | 
|  | 651         GURL(), 111, | 
|  | 652         AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_)); | 
|  | 653     EXPECT_TRUE(job->is_delivering_appcache_response()); | 
|  | 654 | 
|  | 655     // Start the request. | 
|  | 656     EXPECT_FALSE(job->has_been_started()); | 
|  | 657     mock_factory_job_ = job; | 
|  | 658     request_->Start(); | 
|  | 659     EXPECT_FALSE(mock_factory_job_); | 
|  | 660     EXPECT_TRUE(job->has_been_started()); | 
|  | 661     // Completion is async. | 
|  | 662   } | 
|  | 663 | 
|  | 664   void VerifyDeliverPartialResponse() { | 
|  | 665     EXPECT_TRUE(request_->status().is_success()); | 
|  | 666     EXPECT_EQ(3, url_request_delegate_->amount_received_); | 
|  | 667     EXPECT_EQ(0, memcmp(kHttpBasicBody + 1, | 
|  | 668                         url_request_delegate_->received_data_->data(), | 
|  | 669                         3)); | 
|  | 670     net::HttpResponseHeaders* headers = | 
|  | 671         url_request_delegate_->received_info_.headers.get(); | 
|  | 672     EXPECT_EQ(206, headers->response_code()); | 
|  | 673     EXPECT_EQ(3, headers->GetContentLength()); | 
|  | 674     int64 range_start, range_end, object_size; | 
|  | 675     EXPECT_TRUE( | 
|  | 676         headers->GetContentRange(&range_start, &range_end, &object_size)); | 
|  | 677     EXPECT_EQ(1, range_start); | 
|  | 678     EXPECT_EQ(3, range_end); | 
|  | 679     EXPECT_EQ(5, object_size); | 
|  | 680     TestFinished(); | 
|  | 681   } | 
|  | 682 | 
| 620   // CancelRequest -------------------------------------- | 683   // CancelRequest -------------------------------------- | 
| 621 | 684 | 
| 622   void CancelRequest() { | 685   void CancelRequest() { | 
| 623     // This test has several async steps. | 686     // This test has several async steps. | 
| 624     // 1. Write a large response to response storage. | 687     // 1. Write a large response to response storage. | 
| 625     // 2. Use URLRequest to retrieve it. | 688     // 2. Use URLRequest to retrieve it. | 
| 626     // 3. Cancel the request after data starts coming in. | 689     // 3. Cancel the request after data starts coming in. | 
| 627 | 690 | 
| 628     PushNextTask(NewRunnableMethod( | 691     PushNextTask(NewRunnableMethod( | 
| 629        this, &AppCacheURLRequestJobTest::VerifyCancel)); | 692        this, &AppCacheURLRequestJobTest::VerifyCancel)); | 
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 725 } | 788 } | 
| 726 | 789 | 
| 727 TEST_F(AppCacheURLRequestJobTest, DeliverSmallAppCachedResponse) { | 790 TEST_F(AppCacheURLRequestJobTest, DeliverSmallAppCachedResponse) { | 
| 728   RunTestOnIOThread(&AppCacheURLRequestJobTest::DeliverSmallAppCachedResponse); | 791   RunTestOnIOThread(&AppCacheURLRequestJobTest::DeliverSmallAppCachedResponse); | 
| 729 } | 792 } | 
| 730 | 793 | 
| 731 TEST_F(AppCacheURLRequestJobTest, DeliverLargeAppCachedResponse) { | 794 TEST_F(AppCacheURLRequestJobTest, DeliverLargeAppCachedResponse) { | 
| 732   RunTestOnIOThread(&AppCacheURLRequestJobTest::DeliverLargeAppCachedResponse); | 795   RunTestOnIOThread(&AppCacheURLRequestJobTest::DeliverLargeAppCachedResponse); | 
| 733 } | 796 } | 
| 734 | 797 | 
|  | 798 TEST_F(AppCacheURLRequestJobTest, DeliverPartialResponse) { | 
|  | 799   RunTestOnIOThread(&AppCacheURLRequestJobTest::DeliverPartialResponse); | 
|  | 800 } | 
|  | 801 | 
| 735 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { | 802 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { | 
| 736   RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); | 803   RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); | 
| 737 } | 804 } | 
| 738 | 805 | 
| 739 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { | 806 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { | 
| 740   RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); | 807   RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); | 
| 741 } | 808 } | 
| 742 | 809 | 
| 743 }  // namespace appcache | 810 }  // namespace appcache | 
| 744 | 811 | 
| 745 // AppCacheURLRequestJobTest is expected to always live longer than the | 812 // AppCacheURLRequestJobTest is expected to always live longer than the | 
| 746 // runnable methods.  This lets us call NewRunnableMethod on its instances. | 813 // runnable methods.  This lets us call NewRunnableMethod on its instances. | 
| 747 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheURLRequestJobTest); | 814 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheURLRequestJobTest); | 
| OLD | NEW | 
|---|