diff options
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/http_cache.cc | 1 | ||||
-rw-r--r-- | net/http/http_cache_unittest.cc | 34 |
2 files changed, 32 insertions, 3 deletions
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index 7e73d94..3758a51 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -902,6 +902,7 @@ void HttpCache::OnIOComplete(int result, PendingOp* pending_op) { if (op == WI_CREATE_ENTRY) pending_op->disk_entry->Doom(); pending_op->disk_entry->Close(); + pending_op->disk_entry = NULL; fail_requests = true; } } diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc index f48899c..dc114da 100644 --- a/net/http/http_cache_unittest.cc +++ b/net/http/http_cache_unittest.cc @@ -369,9 +369,7 @@ class MockDiskCache : public disk_cache::Backend { } ~MockDiskCache() { - EntryMap::iterator it = entries_.begin(); - for (; it != entries_.end(); ++it) - it->second->Release(); + ReleaseAll(); } virtual int32 GetEntryCount() const { @@ -496,6 +494,13 @@ class MockDiskCache : public disk_cache::Backend { // Return entries that fail some of their requests. void set_soft_failures(bool value) { soft_failures_ = value; } + void ReleaseAll() { + EntryMap::iterator it = entries_.begin(); + for (; it != entries_.end(); ++it) + it->second->Release(); + entries_.clear(); + } + private: typedef base::hash_map<std::string, MockDiskEntry*> EntryMap; @@ -1720,6 +1725,29 @@ TEST(HttpCache, SimpleGET_ManyWriters_CancelCreate) { } } +// Tests that we can cancel a single request to open a disk cache entry. +TEST(HttpCache, SimpleGET_CancelCreate) { + MockHttpCache cache; + + MockHttpRequest request(kSimpleGET_Transaction); + + Context* c = new Context(); + + c->result = cache.http_cache()->CreateTransaction(&c->trans); + EXPECT_EQ(net::OK, c->result); + + c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog()); + EXPECT_EQ(net::ERR_IO_PENDING, c->result); + + // Release the reference that the mock disk cache keeps for this entry, so + // that we test that the http cache handles the cancelation correctly. + cache.disk_cache()->ReleaseAll(); + delete c; + + MessageLoop::current()->RunAllPending(); + EXPECT_EQ(1, cache.disk_cache()->create_count()); +} + // Tests that we delete/create entries even if multiple requests are queued. TEST(HttpCache, SimpleGET_ManyWriters_BypassCache) { MockHttpCache cache; |