Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: net/http/http_cache_unittest.cc

Issue 23710059: Release the cache entry on deferred redirect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disable new tests on Chrome Frame Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_cache.h" 5 #include "net/http/http_cache.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 5305 matching lines...) Expand 10 before | Expand all | Expand 10 after
5316 5316
5317 // force this transaction to validate the cache 5317 // force this transaction to validate the cache
5318 MockTransaction transaction(kETagGET_Transaction); 5318 MockTransaction transaction(kETagGET_Transaction);
5319 transaction.load_flags |= net::LOAD_VALIDATE_CACHE; 5319 transaction.load_flags |= net::LOAD_VALIDATE_CACHE;
5320 RunTransactionTest(cache.http_cache(), transaction); 5320 RunTransactionTest(cache.http_cache(), transaction);
5321 5321
5322 // read from the cache 5322 // read from the cache
5323 RunTransactionTest(cache.http_cache(), kETagGET_Transaction); 5323 RunTransactionTest(cache.http_cache(), kETagGET_Transaction);
5324 } 5324 }
5325 5325
5326 TEST(HttpCache, CachedRedirect) { 5326 TEST(HttpCache, CachedRedirect) {
rvargas (doing something else) 2013/09/17 19:53:25 I think is better to write a new test closer to th
davidben 2013/09/17 22:16:04 Added an HttpCache.DiscardedResponse. Did you mean
5327 MockHttpCache cache; 5327 MockHttpCache cache;
5328 5328
5329 ScopedMockTransaction kTestTransaction(kSimpleGET_Transaction); 5329 ScopedMockTransaction kTestTransaction(kSimpleGET_Transaction);
5330 kTestTransaction.status = "HTTP/1.1 301 Moved Permanently"; 5330 kTestTransaction.status = "HTTP/1.1 301 Moved Permanently";
5331 kTestTransaction.response_headers = "Location: http://www.bar.com/\n"; 5331 kTestTransaction.response_headers = "Location: http://www.bar.com/\n";
5332 5332
5333 MockHttpRequest request(kTestTransaction); 5333 MockHttpRequest request(kTestTransaction);
5334 net::TestCompletionCallback callback; 5334 net::TestCompletionCallback callback;
5335 5335
5336 // write to the cache 5336 // Write to the cache.
5337 { 5337 {
5338 scoped_ptr<net::HttpTransaction> trans; 5338 scoped_ptr<net::HttpTransaction> trans;
5339 int rv = cache.http_cache()->CreateTransaction( 5339 int rv = cache.http_cache()->CreateTransaction(
5340 net::DEFAULT_PRIORITY, &trans, NULL); 5340 net::DEFAULT_PRIORITY, &trans, NULL);
5341 EXPECT_EQ(net::OK, rv); 5341 EXPECT_EQ(net::OK, rv);
5342 ASSERT_TRUE(trans.get()); 5342 ASSERT_TRUE(trans.get());
5343 5343
5344 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); 5344 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
5345 if (rv == net::ERR_IO_PENDING) 5345 if (rv == net::ERR_IO_PENDING)
5346 rv = callback.WaitForResult(); 5346 rv = callback.WaitForResult();
5347 ASSERT_EQ(net::OK, rv); 5347 ASSERT_EQ(net::OK, rv);
5348 5348
5349 const net::HttpResponseInfo* info = trans->GetResponseInfo(); 5349 const net::HttpResponseInfo* info = trans->GetResponseInfo();
5350 ASSERT_TRUE(info); 5350 ASSERT_TRUE(info);
5351 5351
5352 EXPECT_EQ(info->headers->response_code(), 301); 5352 EXPECT_EQ(info->headers->response_code(), 301);
5353 5353
5354 std::string location; 5354 std::string location;
5355 info->headers->EnumerateHeader(NULL, "Location", &location); 5355 info->headers->EnumerateHeader(NULL, "Location", &location);
5356 EXPECT_EQ(location, "http://www.bar.com/"); 5356 EXPECT_EQ(location, "http://www.bar.com/");
5357 5357
5358 // Mark the transaction as completed so it is cached.
5359 trans->DoneReading();
5360
5358 // Destroy transaction when going out of scope. We have not actually 5361 // Destroy transaction when going out of scope. We have not actually
5359 // read the response body -- want to test that it is still getting cached. 5362 // read the response body -- want to test that it is still getting cached.
5360 } 5363 }
5361 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 5364 EXPECT_EQ(1, cache.network_layer()->transaction_count());
5362 EXPECT_EQ(0, cache.disk_cache()->open_count()); 5365 EXPECT_EQ(0, cache.disk_cache()->open_count());
5363 EXPECT_EQ(1, cache.disk_cache()->create_count()); 5366 EXPECT_EQ(1, cache.disk_cache()->create_count());
5364 5367
5365 // read from the cache 5368 // Active entries in the cache are not retired synchronously. Make
5369 // sure the next run hits the MockHttpCache and open_count is
5370 // correct.
5371 base::MessageLoop::current()->RunUntilIdle();
5372
5373 // Read from the cache.
5366 { 5374 {
5367 scoped_ptr<net::HttpTransaction> trans; 5375 scoped_ptr<net::HttpTransaction> trans;
5368 int rv = cache.http_cache()->CreateTransaction( 5376 int rv = cache.http_cache()->CreateTransaction(
5369 net::DEFAULT_PRIORITY, &trans, NULL); 5377 net::DEFAULT_PRIORITY, &trans, NULL);
5370 EXPECT_EQ(net::OK, rv); 5378 EXPECT_EQ(net::OK, rv);
5371 ASSERT_TRUE(trans.get()); 5379 ASSERT_TRUE(trans.get());
5372 5380
5373 rv = trans->Start(&request, callback.callback(), net::BoundNetLog()); 5381 rv = trans->Start(&request, callback.callback(), net::BoundNetLog());
5374 if (rv == net::ERR_IO_PENDING) 5382 if (rv == net::ERR_IO_PENDING)
5375 rv = callback.WaitForResult(); 5383 rv = callback.WaitForResult();
5376 ASSERT_EQ(net::OK, rv); 5384 ASSERT_EQ(net::OK, rv);
5377 5385
5378 const net::HttpResponseInfo* info = trans->GetResponseInfo(); 5386 const net::HttpResponseInfo* info = trans->GetResponseInfo();
5379 ASSERT_TRUE(info); 5387 ASSERT_TRUE(info);
5380 5388
5381 EXPECT_EQ(info->headers->response_code(), 301); 5389 EXPECT_EQ(info->headers->response_code(), 301);
5382 5390
5383 std::string location; 5391 std::string location;
5384 info->headers->EnumerateHeader(NULL, "Location", &location); 5392 info->headers->EnumerateHeader(NULL, "Location", &location);
5385 EXPECT_EQ(location, "http://www.bar.com/"); 5393 EXPECT_EQ(location, "http://www.bar.com/");
5386 5394
5395 // Mark the transaction as completed so it is cached.
5396 trans->DoneReading();
5397
5387 // Destroy transaction when going out of scope. We have not actually 5398 // Destroy transaction when going out of scope. We have not actually
5388 // read the response body -- want to test that it is still getting cached. 5399 // read the response body -- want to test that it is still getting cached.
5389 } 5400 }
5390 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 5401 EXPECT_EQ(1, cache.network_layer()->transaction_count());
5391 EXPECT_EQ(1, cache.disk_cache()->open_count()); 5402 EXPECT_EQ(1, cache.disk_cache()->open_count());
5392 EXPECT_EQ(1, cache.disk_cache()->create_count()); 5403 EXPECT_EQ(1, cache.disk_cache()->create_count());
5393 } 5404 }
5394 5405
5395 // Verify that no-cache resources are stored in cache, but are not fetched from 5406 // Verify that no-cache resources are stored in cache, but are not fetched from
5396 // cache during normal loads. 5407 // cache during normal loads.
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
6162 trans->SetPriority(net::HIGHEST); 6173 trans->SetPriority(net::HIGHEST);
6163 // Should trigger a new network transaction and pick up the new 6174 // Should trigger a new network transaction and pick up the new
6164 // priority. 6175 // priority.
6165 ReadAndVerifyTransaction(trans.get(), transaction); 6176 ReadAndVerifyTransaction(trans.get(), transaction);
6166 6177
6167 EXPECT_EQ(net::HIGHEST, 6178 EXPECT_EQ(net::HIGHEST,
6168 cache.network_layer()->last_create_transaction_priority()); 6179 cache.network_layer()->last_create_transaction_priority());
6169 6180
6170 RemoveMockTransaction(&kRangeGET_TransactionOK); 6181 RemoveMockTransaction(&kRangeGET_TransactionOK);
6171 } 6182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698