summaryrefslogtreecommitdiffstats
path: root/net/http/http_cache_unittest.cc
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-20 21:18:29 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-20 21:18:29 +0000
commita79837898c13790be9b7094e16b98a01288b4687 (patch)
tree41eac04be02116e85e657a4c03cf69a1e3c58163 /net/http/http_cache_unittest.cc
parentc2cb8549159ac80ce1d587445513fae5942e568d (diff)
downloadchromium_src-a79837898c13790be9b7094e16b98a01288b4687.zip
chromium_src-a79837898c13790be9b7094e16b98a01288b4687.tar.gz
chromium_src-a79837898c13790be9b7094e16b98a01288b4687.tar.bz2
Http cache: Fix the code that handles 206s when revalidating
a range from the cache. BUG=12258 TEST=unittests Review URL: http://codereview.chromium.org/174039 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23881 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_cache_unittest.cc')
-rw-r--r--net/http/http_cache_unittest.cc46
1 files changed, 45 insertions, 1 deletions
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index 96118d8..14299b0 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -465,13 +465,19 @@ class RangeTransactionServer {
public:
RangeTransactionServer() {
not_modified_ = false;
+ modified_ = false;
}
~RangeTransactionServer() {
not_modified_ = false;
+ modified_ = false;
}
+ // Returns only 416 or 304 when set.
void set_not_modified(bool value) { not_modified_ = value; }
+ // Returns 206 when revalidating a range (instead of 304).
+ void set_modified(bool value) { modified_ = value; }
+
static void RangeHandler(const net::HttpRequestInfo* request,
std::string* response_status,
std::string* response_headers,
@@ -479,9 +485,11 @@ class RangeTransactionServer {
private:
static bool not_modified_;
+ static bool modified_;
DISALLOW_COPY_AND_ASSIGN(RangeTransactionServer);
};
bool RangeTransactionServer::not_modified_ = false;
+bool RangeTransactionServer::modified_ = false;
// Static.
void RangeTransactionServer::RangeHandler(const net::HttpRequestInfo* request,
@@ -519,7 +527,8 @@ void RangeTransactionServer::RangeHandler(const net::HttpRequestInfo* request,
start, end);
response_headers->append(content_range);
- if (request->extra_headers.find("If-None-Match") == std::string::npos) {
+ if (request->extra_headers.find("If-None-Match") == std::string::npos ||
+ modified_) {
EXPECT_EQ(9, (end - start) % 10);
std::string data;
for (int block_start = start; block_start < end; block_start += 10)
@@ -1766,6 +1775,41 @@ TEST(HttpCache, DISABLED_RangeGET_304) {
RemoveMockTransaction(&kRangeGET_TransactionOK);
}
+// Tests that we deal with 206s when revalidating range requests.
+TEST(HttpCache, DISABLED_RangeGET_ModifiedResult) {
+ MockHttpCache cache;
+ AddMockTransaction(&kRangeGET_TransactionOK);
+ std::string headers;
+
+ // Write to the cache (40-49).
+ RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK,
+ &headers);
+
+ EXPECT_TRUE(Verify206Response(headers, 40, 49));
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
+ EXPECT_EQ(0, cache.disk_cache()->open_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
+
+ // Attempt to read from the cache (40-49).
+ RangeTransactionServer handler;
+ handler.set_modified(true);
+ RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK,
+ &headers);
+
+ EXPECT_TRUE(Verify206Response(headers, 40, 49));
+ EXPECT_EQ(2, cache.network_layer()->transaction_count());
+ EXPECT_EQ(1, cache.disk_cache()->open_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
+
+ // And the entry should be gone.
+ RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK);
+ EXPECT_EQ(3, cache.network_layer()->transaction_count());
+ EXPECT_EQ(1, cache.disk_cache()->open_count());
+ EXPECT_EQ(2, cache.disk_cache()->create_count());
+
+ RemoveMockTransaction(&kRangeGET_TransactionOK);
+}
+
// Tests that we can cache range requests when the start or end is unknown.
// We start with one suffix request, followed by a request from a given point.
TEST(HttpCache, DISABLED_UnknownRangeGET_1) {