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

Unified Diff: net/http/http_cache_unittest.cc

Issue 52028: Net module changes to support caching responses to a POST request. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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.cc ('k') | net/http/http_request_info.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 12361)
+++ net/http/http_cache_unittest.cc (working copy)
@@ -33,7 +33,23 @@
MockDiskEntry(const std::string& key)
: key_(key), doomed_(false), platform_file_(global_platform_file_) {
- const MockTransaction* t = FindMockTransaction(GURL(key));
+ //
+ // 'key' is prefixed with an identifier if it corresponds to a cached POST.
+ // Skip past that to locate the actual URL.
+ //
+ // TODO(darin): It breaks the abstraction a bit that we assume 'key' is an
+ // URL corresponding to a registered MockTransaction. It would be good to
+ // have another way to access the test_mode.
+ //
+ GURL url;
+ if (isdigit(key[0])) {
+ size_t slash = key.find('/');
+ DCHECK(slash != std::string::npos);
+ url = GURL(key.substr(slash + 1));
+ } else {
+ url = GURL(key);
+ }
+ const MockTransaction* t = FindMockTransaction(url);
DCHECK(t);
test_mode_ = t->test_mode;
}
@@ -274,9 +290,9 @@
EXPECT_EQ(0, memcmp(trans_info.data, content.data(), content.size()));
}
-void RunTransactionTest(net::HttpCache* cache,
- const MockTransaction& trans_info) {
- MockHttpRequest request(trans_info);
+void RunTransactionTestWithRequest(net::HttpCache* cache,
+ const MockTransaction& trans_info,
+ const MockHttpRequest& request) {
TestCompletionCallback callback;
// write to the cache
@@ -295,6 +311,12 @@
ReadAndVerifyTransaction(trans.get(), trans_info);
}
+void RunTransactionTest(net::HttpCache* cache,
+ const MockTransaction& trans_info) {
+ return RunTransactionTestWithRequest(
+ cache, trans_info, MockHttpRequest(trans_info));
+}
+
// This class provides a handler for kFastNoStoreGET_Transaction so that the
// no-store header can be included on demand.
class FastTransactionServer {
@@ -897,9 +919,8 @@
TEST(HttpCache, SimplePOST_SkipsCache) {
MockHttpCache cache;
- // Test that we skip the cache for POST requests. Eventually, we will want
- // to cache these, but we'll still have cases where skipping the cache makes
- // sense, so we want to make sure that it works properly.
+ // Test that we skip the cache for POST requests that do not have an upload
+ // identifier.
RunTransactionTest(cache.http_cache(), kSimplePOST_Transaction);
@@ -937,6 +958,36 @@
EXPECT_EQ(0, cache.disk_cache()->create_count());
}
+TEST(HttpCache, SimplePOST_LoadOnlyFromCache_Hit) {
+ MockHttpCache cache;
+
+ // Test that we hit the cache for POST requests.
+
+ MockTransaction transaction(kSimplePOST_Transaction);
+
+ const int64 kUploadId = 1; // Just a dummy value.
+
+ MockHttpRequest request(transaction);
+ request.upload_data = new net::UploadData();
+ request.upload_data->set_identifier(kUploadId);
+ request.upload_data->AppendBytes("hello", 5);
+
+ // Populate the cache.
+ RunTransactionTestWithRequest(cache.http_cache(), transaction, request);
+
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
+ EXPECT_EQ(0, cache.disk_cache()->open_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
+
+ // Load from cache.
+ request.load_flags |= net::LOAD_ONLY_FROM_CACHE;
+ RunTransactionTestWithRequest(cache.http_cache(), transaction, request);
+
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
+ EXPECT_EQ(1, cache.disk_cache()->open_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
+}
+
TEST(HttpCache, RangeGET_SkipsCache) {
MockHttpCache cache;
« no previous file with comments | « net/http/http_cache.cc ('k') | net/http/http_request_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698