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 | |
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')
-rw-r--r-- | webkit/appcache/appcache_url_request_job.cc | 16 | ||||
-rw-r--r-- | webkit/appcache/appcache_url_request_job.h | 2 | ||||
-rw-r--r-- | webkit/appcache/appcache_url_request_job_unittest.cc | 67 |
3 files changed, 79 insertions, 6 deletions
diff --git a/webkit/appcache/appcache_url_request_job.cc b/webkit/appcache/appcache_url_request_job.cc index ea9ea9a..05a5016 100644 --- a/webkit/appcache/appcache_url_request_job.cc +++ b/webkit/appcache/appcache_url_request_job.cc @@ -9,6 +9,7 @@ #include "base/message_loop.h" #include "base/string_util.h" #include "net/base/net_errors.h" +#include "net/http/http_request_headers.h" #include "net/http/http_util.h" #include "net/url_request/url_request_status.h" @@ -243,13 +244,18 @@ bool AppCacheURLRequestJob::ReadRawData(net::IOBuffer* buf, int buf_size, } void AppCacheURLRequestJob::SetExtraRequestHeaders( - const std::string& headers) { - // If multiple ranges are requested, we play dumb and - // return the entire response with 200 OK. + const net::HttpRequestHeaders& headers) { + std::string value; std::vector<net::HttpByteRange> ranges; - if (!net::HttpUtil::ParseRanges(headers, &ranges) || (ranges.size() > 1U)) + if (!headers.GetHeader(net::HttpRequestHeaders::kRange, &value) || + !net::HttpUtil::ParseRangeHeader(value, &ranges)) { return; - range_requested_ = ranges[0]; + } + + // If multiple ranges are requested, we play dumb and + // return the entire response with 200 OK. + if (ranges.size() == 1U) + range_requested_ = ranges[0]; } } // namespace appcache diff --git a/webkit/appcache/appcache_url_request_job.h b/webkit/appcache/appcache_url_request_job.h index dab6f22..68d8622 100644 --- a/webkit/appcache/appcache_url_request_job.h +++ b/webkit/appcache/appcache_url_request_job.h @@ -108,7 +108,7 @@ class AppCacheURLRequestJob : public URLRequestJob, // Sets extra request headers for Job types that support request headers. // This is how we get informed of range-requests. - virtual void SetExtraRequestHeaders(const std::string& headers); + virtual void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers); // TODO(michaeln): does this apply to our cached responses? // The payload we store should have been fully decoded prior to 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); } |