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

Unified Diff: net/http/http_cache_unittest.cc

Issue 452017: Http cache: Add code to restart a network request when the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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') | net/http/partial_data.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
===================================================================
--- net/http/http_cache_unittest.cc (revision 33307)
+++ net/http/http_cache_unittest.cc (working copy)
@@ -2503,6 +2503,48 @@
RemoveMockTransaction(&transaction);
}
+// Tests that we can handle a regular request to a sparse entry, that results in
+// new content provided by the server (206).
+TEST(HttpCache, GET_Previous206_NewContent) {
+ MockHttpCache cache;
+ cache.http_cache()->set_enable_range_support(true);
+ AddMockTransaction(&kRangeGET_TransactionOK);
+ std::string headers;
+
+ // Write to the cache (0-9).
+ MockTransaction transaction(kRangeGET_TransactionOK);
+ transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER;
+ transaction.data = "rg: 00-09 ";
+ RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
+
+ EXPECT_TRUE(Verify206Response(headers, 0, 9));
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
+ EXPECT_EQ(0, cache.disk_cache()->open_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
+
+ // Now we'll issue a request without any range that should result first in a
+ // 206 (when revalidating), and then in a weird standard answer: the test
+ // server will not modify the response so we'll get the default range... a
+ // real server will answer with 200.
+ MockTransaction transaction2(kRangeGET_TransactionOK);
+ transaction2.request_headers = EXTRA_HEADER;
+ transaction2.data = "rg: 40-49 ";
+ RangeTransactionServer handler;
+ handler.set_modified(true);
+ RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers);
+
+ EXPECT_EQ(0U, headers.find("HTTP/1.1 206 Partial Content\n"));
+ EXPECT_EQ(3, cache.network_layer()->transaction_count());
+ EXPECT_EQ(1, cache.disk_cache()->open_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
+
+ // Verify that the previous request deleted the entry.
+ RunTransactionTest(cache.http_cache(), transaction);
+ EXPECT_EQ(2, cache.disk_cache()->create_count());
+
+ RemoveMockTransaction(&transaction);
+}
+
// Tests that we can handle cached 206 responses that are not sparse.
TEST(HttpCache, GET_Previous206_NotSparse) {
MockHttpCache cache;
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | net/http/partial_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698