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

Unified Diff: net/http/http_cache_unittest.cc

Issue 22926031: Sparse IO: Allow failover to network in debug builds (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: trying another upload, hopefully it will override the previous "old chunk mismatch" Created 7 years, 4 months 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') | net/http/mock_http_cache.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_cache_unittest.cc
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index 82d461ca0aca2887cf12d6b00cd11a3f462efae1..c957450c4eae9c52efe868a74b1d06b9817e28f3 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -3394,6 +3394,82 @@ TEST(HttpCache, RangeGET_OK) {
RemoveMockTransaction(&kRangeGET_TransactionOK);
}
+#if defined(OS_ANDROID)
+
+// Checks that with a cache backend having Sparse IO unimplementes the cache
+// entry would be doomed after a range request.
+// TODO(pasko): remove when the SimpleBackendImpl implements Sparse IO.
+TEST(HttpCache, RangeGET_SparseNotImplemented) {
+ MockHttpCache cache;
+ cache.disk_cache()->set_fail_sparse_requests();
+
+ // Run a cacheable request to prime the cache.
+ MockTransaction transaction(kTypicalGET_Transaction);
+ transaction.url = kRangeGET_TransactionOK.url;
+ AddMockTransaction(&transaction);
+ RunTransactionTest(cache.http_cache(), transaction);
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
+ EXPECT_EQ(0, cache.disk_cache()->open_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
+
+ // Verify that we added the entry.
+ disk_cache::Entry* entry;
+ net::TestCompletionCallback cb;
+ int rv = cache.disk_cache()->OpenEntry(transaction.url,
+ &entry,
+ cb.callback());
+ ASSERT_EQ(net::OK, cb.GetResult(rv));
+ EXPECT_EQ(1, cache.disk_cache()->open_count());
+ entry->Close();
+ RemoveMockTransaction(&transaction);
+
+ // Request the range with the backend that does not support it.
+ MockTransaction transaction2(kRangeGET_TransactionOK);
+ std::string headers;
+ AddMockTransaction(&transaction2);
+ RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers);
+ EXPECT_EQ(2, cache.network_layer()->transaction_count());
+ EXPECT_EQ(2, cache.disk_cache()->open_count());
+ EXPECT_EQ(2, cache.disk_cache()->create_count());
+
+ // Mock cache would return net::ERR_CACHE_OPEN_FAILURE on a doomed entry, even
+ // if it was re-created later, so this effectively checks that the old data is
+ // gone.
+ disk_cache::Entry* entry2;
+ rv = cache.disk_cache()->OpenEntry(transaction2.url,
+ &entry2,
+ cb.callback());
+ ASSERT_EQ(net::ERR_CACHE_OPEN_FAILURE, cb.GetResult(rv));
+ RemoveMockTransaction(&transaction2);
+}
+
+TEST(HttpCache, RangeGET_SparseNotImplementedOnEmptyCache) {
+ MockHttpCache cache;
+ cache.disk_cache()->set_fail_sparse_requests();
+
+ // Request the range with the backend that does not support it.
+ MockTransaction transaction(kRangeGET_TransactionOK);
+ std::string headers;
+ AddMockTransaction(&transaction);
+ RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
+ EXPECT_EQ(0, cache.disk_cache()->open_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
+
+ // Mock cache would return net::ERR_CACHE_OPEN_FAILURE on a doomed entry, even
+ // if it was re-created later, so this effectively checks that the old data is
+ // gone as a result of a failed range write.
+ disk_cache::Entry* entry;
+ net::TestCompletionCallback cb;
+ int rv = cache.disk_cache()->OpenEntry(transaction.url,
+ &entry,
+ cb.callback());
+ ASSERT_EQ(net::ERR_CACHE_OPEN_FAILURE, cb.GetResult(rv));
+ RemoveMockTransaction(&transaction);
+}
+
+#endif // OS_ANDROID
+
// Tests that we can cache range requests and fetch random blocks from the
// cache and the network, with synchronous responses.
TEST(HttpCache, RangeGET_SyncOK) {
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | net/http/mock_http_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698