summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorrvargas@chromium.org <rvargas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-11 00:04:07 +0000
committerrvargas@chromium.org <rvargas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-11 00:04:07 +0000
commit7d84e6431c6388f4a3f417d018709710e5089d5f (patch)
treea3affdf426289ee374f36528792d38a268f127a1 /net
parent8166fb9bab0a8a235adc4045d2fab74ff34d6019 (diff)
downloadchromium_src-7d84e6431c6388f4a3f417d018709710e5089d5f.zip
chromium_src-7d84e6431c6388f4a3f417d018709710e5089d5f.tar.gz
chromium_src-7d84e6431c6388f4a3f417d018709710e5089d5f.tar.bz2
Http cache: Don't delete entries when there is a network error.
BUG=176075 TEST=net_unittests Review URL: https://chromiumcodereview.appspot.com/13852002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193508 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/http/http_cache_transaction.cc2
-rw-r--r--net/http/http_cache_unittest.cc28
2 files changed, 30 insertions, 0 deletions
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc
index fce6bac..94c4513 100644
--- a/net/http/http_cache_transaction.cc
+++ b/net/http/http_cache_transaction.cc
@@ -835,6 +835,8 @@ int HttpCache::Transaction::DoSendRequestComplete(int result) {
const HttpResponseInfo* response = network_trans_->GetResponseInfo();
DCHECK(response);
response_.cert_request_info = response->cert_request_info;
+ } else if (response_.was_cached) {
+ DoneWritingToEntry(true);
}
return result;
}
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index 585e457..b7fe187 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -3029,6 +3029,34 @@ TEST(HttpCache, SimpleDELETE_DontInvalidate_416) {
RemoveMockTransaction(&transaction);
}
+// Tests that we don't invalidate entries after a failed network transaction.
+TEST(HttpCache, SimpleGET_DontInvalidateOnFailure) {
+ MockHttpCache cache;
+
+ // Populate the cache.
+ RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
+
+ // Fail the network request.
+ MockTransaction transaction(kSimpleGET_Transaction);
+ transaction.return_code = net::ERR_FAILED;
+ transaction.load_flags |= net::LOAD_VALIDATE_CACHE;
+
+ AddMockTransaction(&transaction);
+ RunTransactionTest(cache.http_cache(), transaction);
+ EXPECT_EQ(2, cache.network_layer()->transaction_count());
+ RemoveMockTransaction(&transaction);
+
+ transaction.load_flags = net::LOAD_ONLY_FROM_CACHE;
+ transaction.return_code = net::OK;
+ AddMockTransaction(&transaction);
+ RunTransactionTest(cache.http_cache(), transaction);
+
+ // Make sure the transaction didn't reach the network.
+ EXPECT_EQ(2, cache.network_layer()->transaction_count());
+ RemoveMockTransaction(&transaction);
+}
+
TEST(HttpCache, RangeGET_SkipsCache) {
MockHttpCache cache;