Commit 49abb41f authored by rvargas@google.com's avatar rvargas@google.com

Http Cache: Make sure that we don't switch to mode NONE when

StopCaching is called if there is no network transaction, or
the entry is sparse.

BUG=105041, 22900
TEST=net_unittests
Review URL: http://codereview.chromium.org/8633001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111181 0039d316-1c4b-4281-b951-d872f2087c98
parent 0f7daaa7
...@@ -370,7 +370,8 @@ void HttpCache::Transaction::StopCaching() { ...@@ -370,7 +370,8 @@ void HttpCache::Transaction::StopCaching() {
// entry how it is (it will be marked as truncated at destruction), and let // entry how it is (it will be marked as truncated at destruction), and let
// the next piece of code that executes know that we are now reading directly // the next piece of code that executes know that we are now reading directly
// from the net. // from the net.
if (cache_ && entry_ && (mode_ & WRITE)) if (cache_ && entry_ && (mode_ & WRITE) && network_trans_.get() &&
!is_sparse_ && !range_requested_)
mode_ = NONE; mode_ = NONE;
} }
......
...@@ -5223,6 +5223,60 @@ TEST(HttpCache, StopCachingSavesEntry) { ...@@ -5223,6 +5223,60 @@ TEST(HttpCache, StopCachingSavesEntry) {
entry->Close(); entry->Close();
} }
// Tests that we handle truncated enries when StopCaching is called.
TEST(HttpCache, StopCachingTruncatedEntry) {
MockHttpCache cache;
TestOldCompletionCallback callback;
MockHttpRequest request(kRangeGET_TransactionOK);
request.extra_headers.Clear();
request.extra_headers.AddHeaderFromString(EXTRA_HEADER);
AddMockTransaction(&kRangeGET_TransactionOK);
std::string raw_headers("HTTP/1.1 200 OK\n"
"Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
"ETag: \"foo\"\n"
"Accept-Ranges: bytes\n"
"Content-Length: 80\n");
CreateTruncatedEntry(raw_headers, &cache);
{
// Now make a regular request.
scoped_ptr<net::HttpTransaction> trans;
int rv = cache.http_cache()->CreateTransaction(&trans);
EXPECT_EQ(net::OK, rv);
rv = trans->Start(&request, &callback, net::BoundNetLog());
EXPECT_EQ(net::OK, callback.GetResult(rv));
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
rv = trans->Read(buf, 10, &callback);
EXPECT_EQ(callback.GetResult(rv), 10);
// This is actually going to do nothing.
trans->StopCaching();
// We should be able to keep reading.
rv = trans->Read(buf, 256, &callback);
EXPECT_GT(callback.GetResult(rv), 0);
rv = trans->Read(buf, 256, &callback);
EXPECT_GT(callback.GetResult(rv), 0);
rv = trans->Read(buf, 256, &callback);
EXPECT_EQ(callback.GetResult(rv), 0);
}
// Verify that the disk entry was updated.
disk_cache::Entry* entry;
ASSERT_TRUE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry));
EXPECT_EQ(80, entry->GetDataSize(1));
bool truncated = true;
net::HttpResponseInfo response;
EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated));
EXPECT_FALSE(truncated);
entry->Close();
RemoveMockTransaction(&kRangeGET_TransactionOK);
}
// Tests that we detect truncated rersources from the net when there is // Tests that we detect truncated rersources from the net when there is
// a Content-Length header. // a Content-Length header.
TEST(HttpCache, TruncatedByContentLength) { TEST(HttpCache, TruncatedByContentLength) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment