summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrvargas@chromium.org <rvargas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-10 23:59:04 +0000
committerrvargas@chromium.org <rvargas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-10 23:59:04 +0000
commit255c044c6d8713770292b371f4fb202bdde329ed (patch)
treeee74da81a6f4e556e1999c11947ef96711172a49
parent170f479d9e8a3d5067fc38a8416f8c2da98fd817 (diff)
downloadchromium_src-255c044c6d8713770292b371f4fb202bdde329ed.zip
chromium_src-255c044c6d8713770292b371f4fb202bdde329ed.tar.gz
chromium_src-255c044c6d8713770292b371f4fb202bdde329ed.tar.bz2
Http Cache: Consider the case of calling StopCaching with the use of auth.
StopCaching may transition the transaction to passtrhough without taking full account of the current state. As a result, if the transaction requires any form of authentication, we may end up with reading_ being true and no response headers. Now we account for that at the transaction destructor. BUG=277011 TEST=net_unittests R=gavinp@chromium.org Review URL: https://chromiumcodereview.appspot.com/23726023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222407 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/http/http_cache_transaction.cc6
-rw-r--r--net/http/http_cache_unittest.cc39
2 files changed, 41 insertions, 4 deletions
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc
index 4d7aae0..e370822 100644
--- a/net/http/http_cache_transaction.cc
+++ b/net/http/http_cache_transaction.cc
@@ -215,11 +215,11 @@ HttpCache::Transaction::~Transaction() {
cache_io_start_ = base::TimeTicks();
deferred_cache_sensitivity_delay_ = base::TimeDelta();
- if (cache_.get()) {
+ if (cache_) {
if (entry_) {
- bool cancel_request = reading_;
+ bool cancel_request = reading_ && response_.headers;
if (cancel_request) {
- if (partial_.get()) {
+ if (partial_) {
entry_->disk_entry->CancelSparseIO();
} else {
cancel_request &= (response_.headers->response_code() == 200);
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index c957450..01909ae 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -5838,7 +5838,7 @@ TEST(HttpCache, FilterCompletion) {
EXPECT_EQ(1, cache.disk_cache()->create_count());
}
-// Tests that we stop cachining when told.
+// Tests that we stop caching when told.
TEST(HttpCache, StopCachingDeletesEntry) {
MockHttpCache cache;
net::TestCompletionCallback callback;
@@ -5877,6 +5877,43 @@ TEST(HttpCache, StopCachingDeletesEntry) {
EXPECT_EQ(2, cache.disk_cache()->create_count());
}
+// Tests that we stop caching when told, when using auth.
+TEST(HttpCache, StopCachingWithAuthDeletesEntry) {
+ MockHttpCache cache;
+ net::TestCompletionCallback callback;
+ MockTransaction mock_transaction(kSimpleGET_Transaction);
+ mock_transaction.status = "HTTP/1.1 401 Unauthorized";
+ AddMockTransaction(&mock_transaction);
+ MockHttpRequest request(mock_transaction);
+
+ {
+ scoped_ptr<net::HttpTransaction> trans;
+ int rv = cache.http_cache()->CreateTransaction(
+ net::DEFAULT_PRIORITY, &trans, NULL);
+ EXPECT_EQ(net::OK, rv);
+
+ rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
+ EXPECT_EQ(net::OK, callback.GetResult(rv));
+
+ trans->StopCaching();
+
+ scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
+ rv = trans->Read(buf.get(), 10, callback.callback());
+ EXPECT_EQ(callback.GetResult(rv), 10);
+ }
+ RemoveMockTransaction(&mock_transaction);
+
+ // Make sure that the ActiveEntry is gone.
+ base::MessageLoop::current()->RunUntilIdle();
+
+ // Verify that the entry is gone.
+ RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
+
+ EXPECT_EQ(2, cache.network_layer()->transaction_count());
+ EXPECT_EQ(0, cache.disk_cache()->open_count());
+ EXPECT_EQ(2, cache.disk_cache()->create_count());
+}
+
// Tests that when we are told to stop caching we don't throw away valid data.
TEST(HttpCache, StopCachingSavesEntry) {
MockHttpCache cache;