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

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

Issue 27149: Http cache: When adding a transaction to a cache entry,... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_cache.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/hash_tables.h" 7 #include "base/hash_tables.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 if (rv == net::ERR_IO_PENDING) 268 if (rv == net::ERR_IO_PENDING)
269 rv = callback.WaitForResult(); 269 rv = callback.WaitForResult();
270 ASSERT_EQ(net::OK, rv); 270 ASSERT_EQ(net::OK, rv);
271 271
272 const net::HttpResponseInfo* response = trans->GetResponseInfo(); 272 const net::HttpResponseInfo* response = trans->GetResponseInfo();
273 ASSERT_TRUE(response); 273 ASSERT_TRUE(response);
274 274
275 ReadAndVerifyTransaction(trans.get(), trans_info); 275 ReadAndVerifyTransaction(trans.get(), trans_info);
276 } 276 }
277 277
278 // This class provides a handler for kFastNoStoreGET_Transaction so that the
279 // no-store header can be included on demand.
280 class FastTransactionServer {
281 public:
282 FastTransactionServer() {
283 no_store = false;
284 }
285 ~FastTransactionServer() {}
286
287 void set_no_store(bool value) { no_store = value; }
288
289 static void FastNoStoreHandler(const net::HttpRequestInfo* request,
290 std::string* response_status,
291 std::string* response_headers,
292 std::string* response_data) {
293 if (no_store)
294 *response_headers = "Cache-Control: no-store\n";
295 }
296
297 private:
298 static bool no_store;
299 DISALLOW_COPY_AND_ASSIGN(FastTransactionServer);
300 };
301 bool FastTransactionServer::no_store;
302
303 const MockTransaction kFastNoStoreGET_Transaction = {
304 "http://www.google.com/nostore",
305 "GET",
306 "",
307 net::LOAD_VALIDATE_CACHE,
308 "HTTP/1.1 200 OK",
309 "Cache-Control: max-age=10000\n",
310 "<html><body>Google Blah Blah</body></html>",
311 TEST_MODE_SYNC_NET_START,
312 &FastTransactionServer::FastNoStoreHandler,
313 0
314 };
315
278 } // namespace 316 } // namespace
279 317
280 318
281 //----------------------------------------------------------------------------- 319 //-----------------------------------------------------------------------------
282 // tests 320 // tests
283 321
284 322
285 TEST(HttpCache, CreateThenDestroy) { 323 TEST(HttpCache, CreateThenDestroy) {
286 MockHttpCache cache; 324 MockHttpCache cache;
287 325
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 637 EXPECT_EQ(1, cache.network_layer()->transaction_count());
600 EXPECT_EQ(0, cache.disk_cache()->open_count()); 638 EXPECT_EQ(0, cache.disk_cache()->open_count());
601 EXPECT_EQ(1, cache.disk_cache()->create_count()); 639 EXPECT_EQ(1, cache.disk_cache()->create_count());
602 640
603 for (int i = 0; i < kNumTransactions; ++i) { 641 for (int i = 0; i < kNumTransactions; ++i) {
604 Context* c = context_list[i]; 642 Context* c = context_list[i];
605 delete c; 643 delete c;
606 } 644 }
607 } 645 }
608 646
647 // This is a test for http://code.google.com/p/chromium/issues/detail?id=4731.
648 // We may attempt to delete an entry synchronously with the act of adding a new
649 // transaction to said entry.
650 TEST(HttpCache, FastNoStoreGET_DoneWithPending) {
651 MockHttpCache cache;
652
653 // The headers will be served right from the call to Start() the request.
654 MockHttpRequest request(kFastNoStoreGET_Transaction);
655 FastTransactionServer request_handler;
656 AddMockTransaction(&kFastNoStoreGET_Transaction);
657
658 std::vector<Context*> context_list;
659 const int kNumTransactions = 3;
660
661 for (int i = 0; i < kNumTransactions; ++i) {
662 context_list.push_back(
663 new Context(cache.http_cache()->CreateTransaction()));
664
665 Context* c = context_list[i];
666 int rv = c->trans->Start(&request, &c->callback);
667 if (rv != net::ERR_IO_PENDING)
668 c->result = rv;
669 }
670
671 // The first request should be a writer at this point, and the subsequent
672 // requests should be pending.
673
674 EXPECT_EQ(1, cache.network_layer()->transaction_count());
675 EXPECT_EQ(0, cache.disk_cache()->open_count());
676 EXPECT_EQ(1, cache.disk_cache()->create_count());
677
678 // Now, make sure that the second request asks for the entry not to be stored.
679 request_handler.set_no_store(true);
680
681 for (int i = 0; i < kNumTransactions; ++i) {
682 Context* c = context_list[i];
683 if (c->result == net::ERR_IO_PENDING)
684 c->result = c->callback.WaitForResult();
685 ReadAndVerifyTransaction(c->trans.get(), kFastNoStoreGET_Transaction);
686 delete c;
687 }
688
689 EXPECT_EQ(3, cache.network_layer()->transaction_count());
690 EXPECT_EQ(0, cache.disk_cache()->open_count());
691 EXPECT_EQ(2, cache.disk_cache()->create_count());
692
693 RemoveMockTransaction(&kFastNoStoreGET_Transaction);
694 }
695
609 TEST(HttpCache, SimpleGET_ManyWriters_CancelFirst) { 696 TEST(HttpCache, SimpleGET_ManyWriters_CancelFirst) {
610 MockHttpCache cache; 697 MockHttpCache cache;
611 698
612 MockHttpRequest request(kSimpleGET_Transaction); 699 MockHttpRequest request(kSimpleGET_Transaction);
613 700
614 std::vector<Context*> context_list; 701 std::vector<Context*> context_list;
615 const int kNumTransactions = 2; 702 const int kNumTransactions = 2;
616 703
617 for (int i = 0; i < kNumTransactions; ++i) { 704 for (int i = 0; i < kNumTransactions; ++i) {
618 context_list.push_back( 705 context_list.push_back(
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 if (rv == net::ERR_IO_PENDING) 1174 if (rv == net::ERR_IO_PENDING)
1088 rv = callback.WaitForResult(); 1175 rv = callback.WaitForResult();
1089 ASSERT_EQ(net::ERR_CACHE_MISS, rv); 1176 ASSERT_EQ(net::ERR_CACHE_MISS, rv);
1090 } 1177 }
1091 1178
1092 // Ensure that we don't crash by if left-behind transactions. 1179 // Ensure that we don't crash by if left-behind transactions.
1093 TEST(HttpCache, OutlivedTransactions) { 1180 TEST(HttpCache, OutlivedTransactions) {
1094 MockHttpCache* cache = new MockHttpCache; 1181 MockHttpCache* cache = new MockHttpCache;
1095 1182
1096 net::HttpTransaction* trans = cache->http_cache()->CreateTransaction(); 1183 net::HttpTransaction* trans = cache->http_cache()->CreateTransaction();
1097 delete cache; 1184 delete cache;
1098 delete trans; 1185 delete trans;
1099 } 1186 }
OLDNEW
« no previous file with comments | « net/http/http_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698