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

Unified Diff: net/http/http_cache_unittest.cc

Issue 8569005: HTTP Cache: Implement StopCaching(), to avoid caching (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
« no previous file with comments | « 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 110637)
+++ net/http/http_cache_unittest.cc (working copy)
@@ -5139,6 +5139,90 @@
EXPECT_EQ(1, cache.disk_cache()->create_count());
}
+// Tests that we stop cachining when told.
+TEST(HttpCache, StopCachingDeletesEntry) {
+ MockHttpCache cache;
+ TestOldCompletionCallback callback;
+ MockHttpRequest request(kSimpleGET_Transaction);
+
+ {
+ 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);
+
+ 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_EQ(callback.GetResult(rv), 0);
+ }
+
+ // Make sure that the ActiveEntry is gone.
+ MessageLoop::current()->RunAllPending();
+
+ // Verify that the entry is gone.
+ RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
+
+ EXPECT_EQ(2, cache.network_layer()->transaction_count());
+ EXPECT_EQ(0, cache.disk_cache()->open_count());
+ EXPECT_EQ(2, cache.disk_cache()->create_count());
+}
+
+// Tests that when we are told to stop caching we don't throw away valid data.
+TEST(HttpCache, StopCachingSavesEntry) {
+ MockHttpCache cache;
+ TestOldCompletionCallback callback;
+ MockHttpRequest request(kSimpleGET_Transaction);
+
+ {
+ scoped_ptr<net::HttpTransaction> trans;
+ int rv = cache.http_cache()->CreateTransaction(&trans);
+ EXPECT_EQ(net::OK, rv);
+
+ // Force a response that can be resumed.
+ MockTransaction mock_transaction(kSimpleGET_Transaction);
+ AddMockTransaction(&mock_transaction);
+ mock_transaction.response_headers = "Cache-Control: max-age=10000\n"
+ "Content-Length: 42\n"
+ "Etag: foo\n";
+
+ 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);
+
+ 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_EQ(callback.GetResult(rv), 0);
+
+ RemoveMockTransaction(&mock_transaction);
+ }
+
+ // Verify that the entry is marked as incomplete.
+ disk_cache::Entry* entry;
+ ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry));
+ net::HttpResponseInfo response;
+ bool truncated = false;
+ EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated));
+ EXPECT_TRUE(truncated);
+ entry->Close();
+}
+
// Tests that we detect truncated rersources from the net when there is
// a Content-Length header.
TEST(HttpCache, TruncatedByContentLength) {
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698