diff options
author | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-03 02:08:13 +0000 |
---|---|---|
committer | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-03 02:08:13 +0000 |
commit | 150c51dcb5815eb198d58f5b2f35e2b6dca78aa2 (patch) | |
tree | 73b87038221f397f465900d5c8985682415d7d73 /webkit/appcache/appcache_url_request_job_unittest.cc | |
parent | 8e89fa0e96450c686b6a54051e987ee56fac994f (diff) | |
download | chromium_src-150c51dcb5815eb198d58f5b2f35e2b6dca78aa2.zip chromium_src-150c51dcb5815eb198d58f5b2f35e2b6dca78aa2.tar.gz chromium_src-150c51dcb5815eb198d58f5b2f35e2b6dca78aa2.tar.bz2 |
Fix a regression with satisfying range requests out of the appcache and add a unit_test.
TEST=AppCacheURLRequestJobTest.DeliverPartialResponse
BUG=none
Review URL: http://codereview.chromium.org/2876040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51585 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_url_request_job_unittest.cc')
-rw-r--r-- | webkit/appcache/appcache_url_request_job_unittest.cc | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/webkit/appcache/appcache_url_request_job_unittest.cc b/webkit/appcache/appcache_url_request_job_unittest.cc index c067fa6..7ea135e 100644 --- a/webkit/appcache/appcache_url_request_job_unittest.cc +++ b/webkit/appcache/appcache_url_request_job_unittest.cc @@ -617,6 +617,69 @@ class AppCacheURLRequestJobTest : public testing::Test { TestFinished(); } + // DeliverPartialResponse -------------------------------------- + + void DeliverPartialResponse() { + // This test has several async steps. + // 1. Write a small response to response storage. + // 2. Use URLRequest to retrieve it a subset using a range request + // 3. Verify we received what we expected to receive. + PushNextTask(NewRunnableMethod( + this, &AppCacheURLRequestJobTest::VerifyDeliverPartialResponse)); + PushNextTask(NewRunnableMethod( + this, &AppCacheURLRequestJobTest::MakeRangeRequest)); + writer_.reset(service_->storage()->CreateResponseWriter(GURL())); + written_response_id_ = writer_->response_id(); + WriteBasicResponse(); + // Continues async + } + + void MakeRangeRequest() { + AppCacheStorage* storage = service_->storage(); + request_.reset( + new URLRequest(GURL("http://blah/"), url_request_delegate_.get())); + + // Request a range, the 3 middle chars out of 'Hello' + net::HttpRequestHeaders extra_headers; + extra_headers.SetHeader("Range", "bytes= 1-3"); + request_->SetExtraRequestHeaders(extra_headers); + + // Create job with orders to deliver an appcached entry. + scoped_refptr<AppCacheURLRequestJob> job( + new AppCacheURLRequestJob(request_.get(), storage)); + job->DeliverAppCachedResponse( + GURL(), 111, + AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_)); + EXPECT_TRUE(job->is_delivering_appcache_response()); + + // Start the request. + EXPECT_FALSE(job->has_been_started()); + mock_factory_job_ = job; + request_->Start(); + EXPECT_FALSE(mock_factory_job_); + EXPECT_TRUE(job->has_been_started()); + // Completion is async. + } + + void VerifyDeliverPartialResponse() { + EXPECT_TRUE(request_->status().is_success()); + EXPECT_EQ(3, url_request_delegate_->amount_received_); + EXPECT_EQ(0, memcmp(kHttpBasicBody + 1, + url_request_delegate_->received_data_->data(), + 3)); + net::HttpResponseHeaders* headers = + url_request_delegate_->received_info_.headers.get(); + EXPECT_EQ(206, headers->response_code()); + EXPECT_EQ(3, headers->GetContentLength()); + int64 range_start, range_end, object_size; + EXPECT_TRUE( + headers->GetContentRange(&range_start, &range_end, &object_size)); + EXPECT_EQ(1, range_start); + EXPECT_EQ(3, range_end); + EXPECT_EQ(5, object_size); + TestFinished(); + } + // CancelRequest -------------------------------------- void CancelRequest() { @@ -732,6 +795,10 @@ TEST_F(AppCacheURLRequestJobTest, DeliverLargeAppCachedResponse) { RunTestOnIOThread(&AppCacheURLRequestJobTest::DeliverLargeAppCachedResponse); } +TEST_F(AppCacheURLRequestJobTest, DeliverPartialResponse) { + RunTestOnIOThread(&AppCacheURLRequestJobTest::DeliverPartialResponse); +} + TEST_F(AppCacheURLRequestJobTest, CancelRequest) { RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); } |