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..d75001f0e26d4c2d0ac004b4545e98dbaf0b57f6 100644 |
--- a/net/http/http_cache_unittest.cc |
+++ b/net/http/http_cache_unittest.cc |
@@ -501,6 +501,26 @@ const MockTransaction kRangeGET_TransactionOK = { |
net::OK |
}; |
+const MockTransaction kRangeGET_NotReallyARange = { |
+ "http://www.google.com/range", |
+ "GET", |
+ base::Time(), |
+ EXTRA_HEADER, |
+ net::LOAD_NORMAL, |
+ "HTTP/1.1 200 OK", |
+ "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
+ "ETag: \"foo\"\n" |
+ "Accept-Ranges: bytes\n" |
+ "Content-Length: 10\n" |
+ "Cache-Control: max-age=10000\n", |
+ base::Time(), |
+ "Not a range", |
+ TEST_MODE_NORMAL, |
+ &FastTransactionServer::FastNoStoreHandler, |
+ 0, |
+ net::OK |
+}; |
+ |
// Verifies the response headers (|response|) match a partial content |
// response for the range starting at |start| and ending at |end|. |
void Verify206Response(std::string response, int start, int end) { |
@@ -3394,6 +3414,56 @@ TEST(HttpCache, RangeGET_OK) { |
RemoveMockTransaction(&kRangeGET_TransactionOK); |
} |
+#if defined(OS_ANDROID) |
+ |
+// Tests that with a cache backend that does not implement Sparse IO the cache |
+// entry would be re-created on each transaction. |
+// TODO(pasko): remove when the SimpleBackendImpl implements Sparse IO. |
+TEST(HttpCache, RangeGET_SparseNotImplemented) { |
+ MockHttpCache cache; |
+ cache.disk_cache()->set_fail_sparse_requests(); |
+ AddMockTransaction(&kRangeGET_TransactionOK); |
+ std::string headers; |
+ |
+ // Run a cacheable request to prime the cache. |
+ RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_NotReallyARange, |
rvargas (doing something else)
2013/08/28 21:35:47
I would actually prefer following HttpCache.RangeG
pasko
2013/08/28 21:56:28
Done.
pasko
2013/08/28 22:01:43
huh, misunderstood you here. I thought you suggest
rvargas (doing something else)
2013/08/28 22:33:40
Not really following the whole pattern of that tes
|
+ &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()); |
+ EXPECT_EQ(0, cache.disk_cache()->sparse_count()); |
+ |
+ // Write to the cache (40-49). |
+ RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
+ &headers); |
+ |
+ Verify206Response(headers, 40, 49); |
+ EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
+ EXPECT_EQ(1, cache.disk_cache()->open_count()); |
+ EXPECT_EQ(2, cache.disk_cache()->create_count()); |
+ |
+ // Two sparse operations are expected: ReadyForSparseIO() and |
+ // WriteSparseData(). |
+ EXPECT_EQ(2, cache.disk_cache()->sparse_count()); |
+ |
+ // Run the transaction again. |
+ RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
+ &headers); |
+ |
+ Verify206Response(headers, 40, 49); |
+ EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
+ EXPECT_EQ(1, cache.disk_cache()->open_count()); |
+ EXPECT_EQ(3, cache.disk_cache()->create_count()); |
+ |
+ // WriteSparseData() must be invoked. |
+ EXPECT_EQ(3, cache.disk_cache()->sparse_count()); |
+ |
+ RemoveMockTransaction(&kRangeGET_TransactionOK); |
+} |
+ |
+#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) { |