| 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) {
|
|
|