summaryrefslogtreecommitdiffstats
path: root/net/http
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-18 01:31:04 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-18 01:31:04 +0000
commit21e743205216812e6ca165313b7999f94f0fdc3e (patch)
tree5573b0793a03996eeed1fc01050ca33258061afe /net/http
parentabfef857b0e4f5cad1da9ce0f751283292a4aab6 (diff)
downloadchromium_src-21e743205216812e6ca165313b7999f94f0fdc3e.zip
chromium_src-21e743205216812e6ca165313b7999f94f0fdc3e.tar.gz
chromium_src-21e743205216812e6ca165313b7999f94f0fdc3e.tar.bz2
Http cache: Add a test to make sure that the cache
works as expected with synchronous responses. As an added bonus, now changing the default test mode of kRangeGET_TransactionOK doesn't end up with some tests hanging, so it is easy to manually verify that all tests work as expected. BUG=26729 TEST=unittests Review URL: http://codereview.chromium.org/501099 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34914 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r--net/http/http_cache_transaction.cc2
-rw-r--r--net/http/http_cache_unittest.cc74
-rw-r--r--net/http/http_transaction_unittest.h3
3 files changed, 68 insertions, 11 deletions
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc
index a32efc3..918ebad 100644
--- a/net/http/http_cache_transaction.cc
+++ b/net/http/http_cache_transaction.cc
@@ -1604,7 +1604,7 @@ int HttpCache::Transaction::DoOverwriteCachedResponse() {
}
int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) {
- // If this response is a redirect, then we can stop writing now. (We don't
+ // If this response is a redirect, then we can stop writing now. (We don't
// need to cache the response body of a redirect.)
if (response_.headers->IsRedirect(NULL))
DoneWritingToEntry(true);
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index 3a207ab..2a30bf0 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -2287,6 +2287,62 @@ TEST(HttpCache, RangeGET_OK) {
RemoveMockTransaction(&kRangeGET_TransactionOK);
}
+// Tests that we can cache range requests and fetch random blocks from the
+// cache and the network, with synchronous responses.
+TEST(HttpCache, RangeGET_SyncOK) {
+ MockHttpCache cache;
+ cache.http_cache()->set_enable_range_support(true);
+
+ MockTransaction transaction(kRangeGET_TransactionOK);
+ transaction.test_mode = TEST_MODE_SYNC_ALL;
+ AddMockTransaction(&transaction);
+
+ // Write to the cache (40-49).
+ std::string headers;
+ RunTransactionTestWithResponse(cache.http_cache(), transaction, &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());
+
+ // Read from the cache (40-49).
+ RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
+
+ EXPECT_TRUE(Verify206Response(headers, 40, 49));
+ EXPECT_EQ(2, cache.network_layer()->transaction_count());
+ EXPECT_EQ(0, cache.disk_cache()->open_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
+
+ // Make sure we are done with the previous transaction.
+ MessageLoop::current()->RunAllPending();
+
+ // Write to the cache (30-39).
+ transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER;
+ transaction.data = "rg: 30-39 ";
+ RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
+
+ EXPECT_TRUE(Verify206Response(headers, 30, 39));
+ EXPECT_EQ(3, cache.network_layer()->transaction_count());
+ EXPECT_EQ(1, cache.disk_cache()->open_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
+
+ // Make sure we are done with the previous transaction.
+ MessageLoop::current()->RunAllPending();
+
+ // Write and read from the cache (20-59).
+ transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER;
+ transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 ";
+ RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
+
+ EXPECT_TRUE(Verify206Response(headers, 20, 59));
+ EXPECT_EQ(5, cache.network_layer()->transaction_count());
+ EXPECT_EQ(2, cache.disk_cache()->open_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
+
+ RemoveMockTransaction(&transaction);
+}
+
// Tests that we deal with 304s for range requests.
TEST(HttpCache, RangeGET_304) {
MockHttpCache cache;
@@ -2837,8 +2893,7 @@ TEST(HttpCache, RangeGET_Cancel2) {
// read will return while waiting for the network).
scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(5);
rv = c->trans->Read(buf, buf->size(), &c->callback);
- EXPECT_EQ(net::ERR_IO_PENDING, rv);
- rv = c->callback.WaitForResult();
+ EXPECT_EQ(5, c->callback.GetResult(rv));
rv = c->trans->Read(buf, buf->size(), &c->callback);
EXPECT_EQ(net::ERR_IO_PENDING, rv);
@@ -2883,8 +2938,7 @@ TEST(HttpCache, RangeGET_Cancel3) {
// read will return while waiting for the network).
scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(5);
rv = c->trans->Read(buf, buf->size(), &c->callback);
- EXPECT_EQ(net::ERR_IO_PENDING, rv);
- rv = c->callback.WaitForResult();
+ EXPECT_EQ(5, c->callback.GetResult(rv));
rv = c->trans->Read(buf, buf->size(), &c->callback);
EXPECT_EQ(net::ERR_IO_PENDING, rv);
@@ -3353,14 +3407,14 @@ TEST(HttpCache, GET_CancelIncompleteResource) {
Context* c = new Context();
EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans));
- EXPECT_EQ(net::ERR_IO_PENDING, c->trans->Start(&request, &c->callback, NULL));
- EXPECT_EQ(net::OK, c->callback.WaitForResult());
+ int rv = c->trans->Start(&request, &c->callback, NULL);
+ EXPECT_EQ(net::OK, c->callback.GetResult(rv));
// Read 20 bytes from the cache, and 10 from the net.
- EXPECT_EQ(net::ERR_IO_PENDING, c->trans->Read(buf, len, &c->callback));
- EXPECT_EQ(len, c->callback.WaitForResult());
- EXPECT_EQ(net::ERR_IO_PENDING, c->trans->Read(buf, 10, &c->callback));
- EXPECT_EQ(10, c->callback.WaitForResult());
+ rv = c->trans->Read(buf, len, &c->callback);
+ EXPECT_EQ(len, c->callback.GetResult(rv));
+ rv = c->trans->Read(buf, 10, &c->callback);
+ EXPECT_EQ(10, c->callback.GetResult(rv));
// At this point, we are already reading so canceling the request should leave
// a truncated one.
diff --git a/net/http/http_transaction_unittest.h b/net/http/http_transaction_unittest.h
index 2a93237..cffde7a 100644
--- a/net/http/http_transaction_unittest.h
+++ b/net/http/http_transaction_unittest.h
@@ -34,6 +34,9 @@ enum {
TEST_MODE_SYNC_CACHE_START = 1 << 2,
TEST_MODE_SYNC_CACHE_READ = 1 << 3,
TEST_MODE_SYNC_CACHE_WRITE = 1 << 4,
+ TEST_MODE_SYNC_ALL = TEST_MODE_SYNC_NET_START | TEST_MODE_SYNC_NET_READ |
+ TEST_MODE_SYNC_CACHE_START | TEST_MODE_SYNC_CACHE_READ |
+ TEST_MODE_SYNC_CACHE_WRITE
};
typedef void (*MockTransactionHandler)(const net::HttpRequestInfo* request,