diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-09 19:18:41 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-09 19:18:41 +0000 |
commit | b7d05ab3d0cce2d74d24f702641b3f5702584dab (patch) | |
tree | 30511d93a0898c99dd4e4200a78acca34d67a45c /net/http/http_cache_unittest.cc | |
parent | 7de99596feecaa24900a082a721ef8d4f57b47ee (diff) | |
download | chromium_src-b7d05ab3d0cce2d74d24f702641b3f5702584dab.zip chromium_src-b7d05ab3d0cce2d74d24f702641b3f5702584dab.tar.gz chromium_src-b7d05ab3d0cce2d74d24f702641b3f5702584dab.tar.bz2 |
If a server answers a cache validation request with 304 and cache-control:no-store,
we return the cached entry to the requestor but doom the entry so it's not used
in the future.
B=b/1363355
R=darin
TEST=unit test.
Review URL: http://codereview.chromium.org/13273
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6605 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_cache_unittest.cc')
-rw-r--r-- | net/http/http_cache_unittest.cc | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc index 92ac6ca..ab4e26b 100644 --- a/net/http/http_cache_unittest.cc +++ b/net/http/http_cache_unittest.cc @@ -668,6 +668,50 @@ TEST(HttpCache, ETagGET_ConditionalRequest_304) { EXPECT_EQ(1, cache.disk_cache()->create_count()); } +static void ETagGet_ConditionalRequest_NoStore_Handler( + const net::HttpRequestInfo* request, + std::string* response_status, + std::string* response_headers, + std::string* response_data) { + EXPECT_TRUE(request->extra_headers.find("If-None-Match") != + std::string::npos); + response_status->assign("HTTP/1.1 304 Not Modified"); + response_headers->assign("Cache-Control: no-store\n"); + response_data->clear(); +} + +TEST(HttpCache, ETagGET_ConditionalRequest_304_NoStore) { + MockHttpCache cache; + + ScopedMockTransaction transaction(kETagGET_Transaction); + + // Write to the cache. + 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()); + + // Get the same URL again, but this time we expect it to result + // in a conditional request. + transaction.load_flags = net::LOAD_VALIDATE_CACHE; + transaction.handler = ETagGet_ConditionalRequest_NoStore_Handler; + RunTransactionTest(cache.http_cache(), transaction); + + EXPECT_EQ(2, cache.network_layer()->transaction_count()); + EXPECT_EQ(1, cache.disk_cache()->open_count()); + EXPECT_EQ(1, cache.disk_cache()->create_count()); + + ScopedMockTransaction transaction2(kETagGET_Transaction); + + // Write to the cache again. This should create a new entry. + RunTransactionTest(cache.http_cache(), transaction2); + + EXPECT_EQ(3, cache.network_layer()->transaction_count()); + EXPECT_EQ(1, cache.disk_cache()->open_count()); + EXPECT_EQ(2, cache.disk_cache()->create_count()); +} + TEST(HttpCache, SimplePOST_SkipsCache) { MockHttpCache cache; |