diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-20 23:16:00 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-20 23:16:00 +0000 |
commit | 8a92555e667090d8c6592ebe670628ca33b86ef0 (patch) | |
tree | 868af9bb38ff9fa9c25a68c9d27fa5ede9d21e92 | |
parent | f8f8250237f535750e0d8269d2762f52db090e45 (diff) | |
download | chromium_src-8a92555e667090d8c6592ebe670628ca33b86ef0.zip chromium_src-8a92555e667090d8c6592ebe670628ca33b86ef0.tar.gz chromium_src-8a92555e667090d8c6592ebe670628ca33b86ef0.tar.bz2 |
Http cache: Make sure that when we cancel a request for
a truncated entry, we keep the truncation flag.
BUG=27276
TEST=unittests
Review URL: http://codereview.chromium.org/422002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32707 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/http/http_cache_transaction.cc | 2 | ||||
-rw-r--r-- | net/http/http_cache_unittest.cc | 67 |
2 files changed, 68 insertions, 1 deletions
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc index 789a1a2..cdc4ecc 100644 --- a/net/http/http_cache_transaction.cc +++ b/net/http/http_cache_transaction.cc @@ -458,7 +458,7 @@ bool HttpCache::Transaction::AddTruncatedFlag() { DCHECK(mode_ & WRITE); // Don't set the flag for sparse entries. - if (partial_.get()) + if (partial_.get() && !truncated_) return true; // Double check that there is something worth keeping. diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc index f1e636b..dbcd3b1 100644 --- a/net/http/http_cache_unittest.cc +++ b/net/http/http_cache_unittest.cc @@ -3224,6 +3224,73 @@ TEST(HttpCache, GET_IncompleteResource) { entry->Close(); } +// Tests that when we cancel a request that was interrupted, we mark it again +// as truncated. +TEST(HttpCache, GET_CancelIncompleteResource) { + MockHttpCache cache; + cache.http_cache()->set_enable_range_support(true); + AddMockTransaction(&kRangeGET_TransactionOK); + + // Create a disk cache entry that stores an incomplete resource. + disk_cache::Entry* entry; + ASSERT_TRUE(cache.disk_cache()->CreateEntry(kRangeGET_TransactionOK.url, + &entry)); + + // Content-length will be intentionally bogus. + std::string raw_headers("HTTP/1.1 200 OK\n" + "Last-Modified: something\n" + "ETag: \"foo\"\n" + "Accept-Ranges: bytes\n" + "Content-Length: 10\n"); + raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(), + raw_headers.size()); + + net::HttpResponseInfo response; + response.headers = new net::HttpResponseHeaders(raw_headers); + + // Set the last argument for this to be an incomplete request. + EXPECT_TRUE(net::HttpCache::WriteResponseInfo(entry, &response, true, true)); + + scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(100)); + int len = static_cast<int>(base::strlcpy(buf->data(), "rg: 00-09 rg: 10-19 ", + buf->size())); + EXPECT_EQ(len, entry->WriteData(1, 0, buf, len, NULL, true)); + + // Now make a regular request. + MockTransaction transaction(kRangeGET_TransactionOK); + transaction.request_headers = EXTRA_HEADER; + + MockHttpRequest request(transaction); + Context* c = new Context(); + EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans)); + + EXPECT_EQ(net::ERR_IO_PENDING, c->trans->Start(&request, &c->callback, NULL)); + EXPECT_EQ(net::OK, c->callback.WaitForResult()); + + // Read 20 bytes from the cache, and 10 from the net. + EXPECT_EQ(net::ERR_IO_PENDING, c->trans->Read(buf, len, &c->callback)); + EXPECT_EQ(len, c->callback.WaitForResult()); + EXPECT_EQ(net::ERR_IO_PENDING, c->trans->Read(buf, 10, &c->callback)); + EXPECT_EQ(10, c->callback.WaitForResult()); + + // At this point, we are already reading so canceling the request should leave + // a truncated one. + delete c; + + RemoveMockTransaction(&kRangeGET_TransactionOK); + + EXPECT_EQ(2, cache.network_layer()->transaction_count()); + EXPECT_EQ(1, cache.disk_cache()->open_count()); + EXPECT_EQ(1, cache.disk_cache()->create_count()); + + // Verify that the disk entry was updated: now we have 30 bytes. + EXPECT_EQ(30, entry->GetDataSize(1)); + bool truncated = false; + EXPECT_TRUE(net::HttpCache::ReadResponseInfo(entry, &response, &truncated)); + EXPECT_TRUE(truncated); + entry->Close(); +} + // Tests that we can handle range requests when we have a truncated entry. TEST(HttpCache, RangeGET_IncompleteResource) { MockHttpCache cache; |