Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(919)

Unified Diff: net/http/http_cache_unittest.cc

Issue 8633001: Http Cache: Make sure that we don't switch to mode NONE when (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« net/http/http_cache_transaction.cc ('K') | « net/http/http_cache_transaction.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_cache_unittest.cc
===================================================================
--- net/http/http_cache_unittest.cc (revision 110737)
+++ net/http/http_cache_unittest.cc (working copy)
@@ -5223,6 +5223,60 @@
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
// a Content-Length header.
TEST(HttpCache, TruncatedByContentLength) {
« net/http/http_cache_transaction.cc ('K') | « net/http/http_cache_transaction.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698